Got a question about interfaces: We make an interface and impelement it as a class which have some public functions those return some values. And then we use those functions with calling the class and use the methods we just created. What is the point interface here? we could just create a normal class with two functions and call them and return the values. I mean what exactly does interface here? In the other words, we could just code: class Table{ public function save(array $data){ return "foo"; } public function log($message){ return $message; } } echo (new Table())->save([]) . " "; echo (new Table())->log(); These line do exactly the same! ?????
The point of interface is that you can implement many interfaces on the same class. And you just create function bodies in interface you can't return a value from an interface function you can just defined the return type of data like this :array.
Interface is a way for you to enforce a pattern. You can create an interface called AnimalsInterface with 2 methods in them; colour() and sound() So every class that implements AnimalsInterface "MUST" have those two methods as well colour() and sound() so; interface AnimalsInterface { public function colour(); public function sound(); } class Cow implements AnimalsInterface { // Must have colour() and sound() methods - otherwise will throw error. } this is useful in big classes, if some other developer tries to remove or change colour() method in Cow class - it won't work. This guarantees every animal classes will have those two methods always.
@athulak response is correct. It may look like its adding complexity but in reality it forces ALL developers to implement whats inside the interface from its keywork IMPLEMENT. Having this, we could be certain that all developers cannot enforce anything they wanted because they want it. Also, as you could see here, Interfaces got no imlementation and just method typed params and returns. Polymorphism is now available. Thanks to it.
Highly appreciated, please create course in Unit and Automated Testing. From beginner to advance for a complete brush up of skills. I will buy it.
Great video so far! You should make a video series on how WordPress was built! :)
Thank you. You have became my new mentor.
😊
You will remember me as I will always thankful to you and the one who comments regularly on this beautiful videos... ❤️❤️
It's my pleasure😊❤✨
Fibonachi Sequence is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34. There are two 1s.
God Bless You
Great Job, Thank you.
😊♥️
thank you 🙏
Glad you like it 😊❤️
Got a question about interfaces:
We make an interface and impelement it as a class which have some public functions those return some values. And then we use those functions with calling the class and use the methods we just created. What is the point interface here? we could just create a normal class with two functions and call them and return the values. I mean what exactly does interface here?
In the other words, we could just code:
class Table{
public function save(array $data){
return "foo";
}
public function log($message){
return $message;
}
}
echo (new Table())->save([]) . "
";
echo (new Table())->log();
These line do exactly the same!
?????
The point of interface is that you can implement many interfaces on the same class.
And you just create function bodies in interface you can't return a value from an interface function you can just defined the return type of data like this :array.
Interface is a way for you to enforce a pattern.
You can create an interface called AnimalsInterface with 2 methods in them; colour() and sound()
So every class that implements AnimalsInterface "MUST" have those two methods as well colour() and sound()
so;
interface AnimalsInterface {
public function colour();
public function sound();
}
class Cow implements AnimalsInterface {
// Must have colour() and sound() methods - otherwise will throw error.
}
this is useful in big classes, if some other developer tries to remove or change colour() method in Cow class - it won't work.
This guarantees every animal classes will have those two methods always.
@athulak response is correct. It may look like its adding complexity but in reality it forces ALL developers to implement whats inside the interface from its keywork IMPLEMENT.
Having this, we could be certain that all developers cannot enforce anything they wanted because they want it.
Also, as you could see here, Interfaces got no imlementation and just method typed params and returns. Polymorphism is now available. Thanks to it.