<?phpclassJuniorCatDoctor{publicfunctionheal(Cat$cat):void{// Many code to heal cat}}classSeniorCatDoctorextendsJuniorCatDoctor{publicfunctionheal(Animal$cat):void{// If cat use standart code to heal cat// Else analises animal and try to heal}}$cat=newCat('Murka');$dog=newDog('Sharik');$juniorDoctor=newJuniorCatDoctor();$seniorDoctor=newSeniorCatDoctor();$juniorDoctor->heal($cat);// $juniorDoctor->heal($dog); // Kernel panic!$seniorDoctor->heal($cat);$seniorDoctor->heal($dog);// Dog still live
classJuniorCatDoctor{heal(cat: Cat):void{// Many code to heal cat}}classSeniorCatDoctorextendsJuniorCatDoctor{heal(cat: Animal):void{// If cat use standart code to heal cat// Else analises animal and try to heal}}constcat=newCat('Murka');constdog=newDog('Sharik');constjuniorDoctor=newJuniorCatDoctor();constseniorDoctor=newSeniorCatDoctor();juniorDoctor.heal(cat);juniorDoctor.heal(dog);// Kernel panic!seniorDoctor.heal(cat);seniorDoctor.heal(dog);// Dog still live
<?phpinterfaceAnimalRepository{publicfunctionfetchAnimal():Animal;}classCatRepositoryimplementsAnimalRepository{publicfunctionfetchAnimal():Cat{returnnewCat('Murka');}}classDogRepositoryimplementsAnimalRepository{publicfunctionfetchAnimal():Dog{returnnewDog('Sharik');}}$cat=(newCatRepository())->fetchAnimal();$dog=(newDogRepository())->fetchAnimal();echo$cat->say();// My name is Murka and I am is a catecho"\n";echo$dog->say();// My name is Sharik and I am is a dog
interfaceAnimalRepository{fetchAnimal():Animal;}classCatRepositoryimplementsAnimalRepository{fetchAnimal():Cat{returnnewCat('Murka');}}classDogRepositoryimplementsAnimalRepository{fetchAnimal():Dog{returnnewDog('Sharik');}}constcat=(newCatRepository()).fetchAnimal();constdog=(newDogRepository()).fetchAnimal();console.log(cat.say());// My name is Murka and I am is a catconsole.log(dog.say());// My name is Sharik and I am is a dog
<?phpclassAnimal{publicfunction__construct(privatestring$name,){}publicfunctionsay():string{return"My name is {$this->name}";}}classCatextendsAnimal{publicfunctionsay():string{returnparent::say()." and I am is a cat";}}classDogextendsAnimal{publicfunctionsay():string{returnparent::say()." and I am is a dog";}}
classAnimal{name: string;constructor(name: string){this.name=name;}say():string{return"My name is "+this.name;}}classCatextendsAnimal{say():string{returnsuper.say()+" and I am is a cat";}meow():string{return"Meow";}}classDogextendsAnimal{say():string{returnsuper.say()+" and I am is a dog";}woof():string{return"Woof";}}
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199