I guess I don't understand. Why write the interface if to still need to call the class/functions of the other class? Even the last part, you still copied and pasted the MySQL class to the new Oracle one.
Answer : you can pass to function as a parametr class object and define in parameter, type of interface that object implements. Then, this function knows that this object has all necessary functions, so no error will occur. Example: myFunc(InterfaceName $object).
If you have to write the function logic of every class method in it's method,then what is the benefit of using that interface? Just for keep using the same methods name but be able cloning from a class name to another?
Php is not statically typed. It makes it hard to see the benefits, but it does a few things. 1. Modularity. You no longer "hard code" the mysql database. As long as the data provider has a function that "listOrders" that returns an array of "Order" objects, it no longer matters where the data is coming from. Whether it's coming from excel, sql, facebook api, etc. Now it becomes easy to add multiple data sources or swap to a new one. 2. Mocking. When testing, you can now hard code a list of Order objects within the listOrders(). This way, it doesn't matter where the data is coming from. You are able to write proper unit tests. As long as that function returns a valid array of "Orders" your application will work as expected. 3. Real world example: I have a table business. I provide wood. I want to get tables. CreateTable(wood): Table As long as a manufacturer takes wood and gives a table, it no longer matters what manufacturer I use. The application will JUST WORK. I can have multiple manufacturers, or swap out manufacturers easily.
Ok, got it. Basically this helpls you in the development phase by forcing you to adhere to a set of rules that implements the interface. Anyone, coming from TypeScript should not have any issue understanding this.
still don't get it , because thats just adding more size to your code while you can define the function + it functionality directly without the interface, i thought its like in C# where you can update something live in the UI using interface , or at least sharing the same triggered information across the app as in C++ and UE blueprint but in php it turn to be a joke , it just define a function name for you thats it . 0 real benefits its like Filling a circle with the same color twice, while the first " Fill " was enough
Ok, got it. Basically this helpls you in the development phase by forcing you to adhere to a set of rules that implements the interface. Anyone, coming from TypeScript should not have any issue understanding this.
For example, say you have 10 classes implementing the same interface, and the interface has one method called echo_text(). You could loop over the 10 instances of those classes and call the echo_text() method on each of the 10 objects and be sure that method exists, without even knowing the implementation of the method.
I don't understand. Why u are using interfaces.. Thoes work done by change class if your other class has same method you can change it your implementation class
I think Interfaces are used to make sure that all function that are needed are present in the class . what he missed was that if you forget to implement those function you get an error. An interface is a sort of contract and it's more about organizing code that provide a funtionality
Very straightforward. Simple to understand
Thank you for good explanation!
I guess I don't understand. Why write the interface if to still need to call the class/functions of the other class? Even the last part, you still copied and pasted the MySQL class to the new Oracle one.
Because the code of the function's implementation in the MySQL and Oracle classes can be different, this is the key thing to understand.
@@clevertechie why code cant be different with same names of functions without that additional interface part?
Answer : you can pass to function as a parametr class object and define in parameter, type of interface that object implements. Then, this function knows that this object has all necessary functions, so no error will occur. Example:
myFunc(InterfaceName $object).
If you have to write the function logic of every class method in it's method,then what is the benefit of using that interface?
Just for keep using the same methods name but be able cloning from a class name to another?
Php is not statically typed. It makes it hard to see the benefits, but it does a few things.
1. Modularity.
You no longer "hard code" the mysql database. As long as the data provider has a function that "listOrders" that returns an array of "Order" objects, it no longer matters where the data is coming from. Whether it's coming from excel, sql, facebook api, etc. Now it becomes easy to add multiple data sources or swap to a new one.
2. Mocking.
When testing, you can now hard code a list of Order objects within the listOrders(). This way, it doesn't matter where the data is coming from. You are able to write proper unit tests. As long as that function returns a valid array of "Orders" your application will work as expected.
3. Real world example:
I have a table business. I provide wood. I want to get tables.
CreateTable(wood): Table
As long as a manufacturer takes wood and gives a table, it no longer matters what manufacturer I use. The application will JUST WORK.
I can have multiple manufacturers, or swap out manufacturers easily.
thanks! finally i got it 👍
2:41 aren't those supposed to called as "function declarations!?
nice, thanks!
I don't seem to grasp the concept of, why would you use Interface if we are using the same name methods inside every classes anyway.
Ok, got it. Basically this helpls you in the development phase by forcing you to adhere to a set of rules that implements the interface. Anyone, coming from TypeScript should not have any issue understanding this.
Perfect.
What is your vscode theme setting including font?
Material Theme Ocean, Font: Consolas, 18
still don't get it ,
because thats just adding more size to your code while you can define the function + it functionality directly without the interface,
i thought its like in C# where you can update something live in the UI using interface , or at least sharing the same triggered information across the app as in C++ and UE blueprint
but in php it turn to be a joke , it just define a function name for you thats it . 0 real benefits
its like Filling a circle with the same color twice, while the first " Fill " was enough
Exactly that is what I am thinking. What is the point tho?
Ok, got it. Basically this helpls you in the development phase by forcing you to adhere to a set of rules that implements the interface. Anyone, coming from TypeScript should not have any issue understanding this.
For example, say you have 10 classes implementing the same interface, and the interface has one method called echo_text(). You could loop over the 10 instances of those classes and call the echo_text() method on each of the 10 objects and be sure that method exists, without even knowing the implementation of the method.
Wow. Been a while???
weird, i've never seen anyone use spaces in their class filenames
When you are creating an object to the actual classes, then why you need an Interface? I mean the interface looks useless here.
You mean Abstraction and Interfaces are same thing
Polymorphism. Abstraction has to do with abstract classes
I don't understand. Why u are using interfaces.. Thoes work done by change class if your other class has same method you can change it your implementation class
I think Interfaces are used to make sure that all function that are needed are present in the class . what he missed was that if you forget to implement those function you get an error. An interface is a sort of contract and it's more about organizing code that provide a funtionality
@@thedude9014 your comment should be pinned
@@thedude9014 You nailed it. That's more precise