V
V
vrazbros2016-12-09 15:56:12
PHP
vrazbros, 2016-12-09 15:56:12

Polymorphism in php live examples?

Hi
Who can give an example of polymorphism from their actual PHP examples ? already tired of reading about the creation of armies of soldiers, cars or figures ....

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Evgrafovich, 2016-12-09
@Tantacula

I have implemented dependency injection for repositories in a Laravel project. The repository inherits a certain interface, and by the name of this interface, classes receive data from the repository. During the development process, instead of the repositories themselves, I introduce an intermediate caching layer that implements the same interface, but gives the cache instead of accessing the database (I won’t give the code, the project is under NDA).
Another example is mock objects when testing. You can also look at frameworks, polymorphism is actively used there, for example, so that you can use different database engines, save files to a remote server via FTP, and not to your own, by changing only one word in the config and without changing the code in your classes.

S
Sergey Zelensky, 2016-12-09
@SergeyZelensky-Rostov

Here is a good article

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question