PHP Polymorphism Example: Show several ways of implementing of polymorphism

Recommend this page to a friend!
  Info   View files Documentation   View files View files (61)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-08-12 (2 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 63 All time: 9,785 This week: 199Up
Version License PHP version Categories
polymorphism 1.0The PHP License5PHP 5, Language, Design Patterns
Description Author

This package can show several ways of implementing of polymorphism in PHP.

It provides examples of PHP code that implement means to create objects that provide the same way to execute the same operations even though the objects are of different classes. Currently it provides examples to implement polimorphism using:

- Without class inheritance
- With class inheritance
- With abstract classes and inheritance
- With interfaces

Picture of Manolo Salsas
  Performance   Level  
Name: Manolo Salsas <contact>
Classes: 7 packages by
Country: Spain Spain
Age: 38
All time rank: 335392 in Spain Spain
Week rank: 488 Up13 in Spain Spain Up
Innovation award
Innovation award
Nominee: 5x

Winner: 1x

Details

Polymorphism

This is a project to explain the polymorphism concept diving into:

  • No inheritance
  • Inheritance
  • Abstraction and inheritance
  • Interface implementation

You can find examples guiding you through all of the steps bellow

  • [Service\Basic][1] uses models from [Model\Basic][2]
  • [Service\Inheritance][3] uses models from [Model\Inheritance][4]
  • [Service\AbstractInheritance][5] uses models from [Model\AbstractInheritance][6]
  • [Service\InterfaceImplementation][7] uses models from [Model\InterfaceImplementation][8]

Extended explanation in spanish can be found [here][9]

[1]: https://github.com/motorflash/polymorphism/tree/master/src/AppBundle/Service/Basic [2]: https://github.com/motorflash/polymorphism/tree/master/src/AppBundle/Model/Basic [3]: https://github.com/motorflash/polymorphism/tree/master/src/AppBundle/Service/Inheritance [4]: https://github.com/motorflash/polymorphism/tree/master/src/AppBundle/Model/Inheritance [5]: https://github.com/motorflash/polymorphism/tree/master/src/AppBundle/Service/AbstractInheritance [6]: https://github.com/motorflash/polymorphism/tree/master/src/AppBundle/Model/AbstractInheritance [7]: https://github.com/motorflash/polymorphism/tree/master/src/AppBundle/Service/InterfaceImplementation [8]: https://github.com/motorflash/polymorphism/tree/master/src/AppBundle/Model/InterfaceImplementation [9]: https://github.com/motorflash/polymorphism/tree/master/docs/polimorfismo.md

Testing

./vendor/bin/phpunit

  Files folder image Files  
File Role Description
Files folder imageapp (3 files, 2 directories)
Files folder imagebin (2 files)
Files folder imagedocs (1 file)
Files folder imagesrc (1 file, 1 directory)
Files folder imagetests (1 directory)
Files folder imagevar (1 file)
Files folder imageweb (7 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  app  
File Role Description
Files folder imageconfig (9 files)
Files folder imageResources (1 directory)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Plain text file AppCache.php Class Class source
  Plain text file AppKernel.php Class Class source

  Files folder image Files  /  app  /  config  
File Role Description
  Accessible without login Plain text file config.yml Data Auxiliary data
  Accessible without login Plain text file config_dev.yml Data Auxiliary data
  Accessible without login Plain text file config_prod.yml Data Auxiliary data
  Accessible without login Plain text file config_test.yml Data Auxiliary data
  Accessible without login Plain text file parameters.yml.dist Data Auxiliary data
  Accessible without login Plain text file routing.yml Data Auxiliary data
  Accessible without login Plain text file routing_dev.yml Data Auxiliary data
  Accessible without login Plain text file security.yml Data Auxiliary data
  Accessible without login Plain text file services.yml Data Auxiliary data

  Files folder image Files  /  app  /  Resources  
File Role Description
Files folder imageviews (1 file, 1 directory)

  Files folder image Files  /  app  /  Resources  /  views  
File Role Description
Files folder imagedefault (1 file)
  Accessible without login Plain text file base.html.twig Data Auxiliary data

  Files folder image Files  /  app  /  Resources  /  views  /  default  
File Role Description
  Accessible without login Plain text file index.html.twig Data Auxiliary data

  Files folder image Files  /  bin  
File Role Description
  Accessible without login Plain text file console Example Example script
  Accessible without login Plain text file symfony_requirements Example Example script

  Files folder image Files  /  docs  
File Role Description
  Accessible without login Plain text file polimorfismo.md Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageAppBundle (1 file, 3 directories)
  Accessible without login Plain text file .htaccess Data Auxiliary data

  Files folder image Files  /  src  /  AppBundle  
File Role Description
Files folder imageController (1 file)
Files folder imageModel (4 directories)
Files folder imageService (4 directories)
  Plain text file AppBundle.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Controller  
File Role Description
  Plain text file DefaultController.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  
File Role Description
Files folder imageAbstractInheritance (5 files)
Files folder imageBasic (2 files)
Files folder imageInheritance (3 files)
Files folder imageInterfaceImplementation (5 files)

  Files folder image Files  /  src  /  AppBundle  /  Model  /  AbstractInheritance  
File Role Description
  Plain text file Animal.php Class Class source
  Plain text file Cat.php Class Class source
  Plain text file Dog.php Class Class source
  Plain text file Lion.php Class Class source
  Plain text file Pet.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Basic  
File Role Description
  Plain text file Cat.php Class Class source
  Plain text file Lion.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  Inheritance  
File Role Description
  Plain text file Animal.php Class Class source
  Plain text file Cat.php Class Class source
  Plain text file Lion.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Model  /  InterfaceImplementation  
File Role Description
  Plain text file Animal.php Class Class source
  Plain text file Cat.php Class Class source
  Plain text file Dog.php Class Class source
  Plain text file Lion.php Class Class source
  Plain text file Pet.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Service  
File Role Description
Files folder imageAbstractInheritance (1 file)
Files folder imageBasic (1 file)
Files folder imageInheritance (1 file)
Files folder imageInterfaceImplementation (1 file)

  Files folder image Files  /  src  /  AppBundle  /  Service  /  AbstractInheritance  
File Role Description
  Plain text file AnimalService.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Service  /  Basic  
File Role Description
  Plain text file AnimalService.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Service  /  Inheritance  
File Role Description
  Plain text file AnimalService.php Class Class source

  Files folder image Files  /  src  /  AppBundle  /  Service  /  InterfaceImplementation  
File Role Description
  Plain text file AnimalService.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageAppBundle (2 directories)

  Files folder image Files  /  tests  /  AppBundle  
File Role Description
Files folder imageModel (2 directories)
Files folder imageService (4 directories)

  Files folder image Files  /  tests  /  AppBundle  /  Model  
File Role Description
Files folder imageBasic (2 files)
Files folder imageInheritance (3 files)

  Files folder image Files  /  tests  /  AppBundle  /  Model  /  Basic  
File Role Description
  Plain text file CatTest.php Class Class source
  Plain text file LionTest.php Class Class source

  Files folder image Files  /  tests  /  AppBundle  /  Model  /  Inheritance  
File Role Description
  Plain text file AnimalTest.php Class Class source
  Plain text file CatTest.php Class Class source
  Plain text file LionTest.php Class Class source

  Files folder image Files  /  tests  /  AppBundle  /  Service  
File Role Description
Files folder imageAbstractInheritance (1 file)
Files folder imageBasic (1 file)
Files folder imageInheritance (1 file)
Files folder imageInterfaceImplementation (1 file)

  Files folder image Files  /  tests  /  AppBundle  /  Service  /  AbstractInheritance  
File Role Description
  Plain text file AnimalServiceTest.php Class Class source

  Files folder image Files  /  tests  /  AppBundle  /  Service  /  Basic  
File Role Description
  Plain text file AnimalServiceTest.php Class Class source

  Files folder image Files  /  tests  /  AppBundle  /  Service  /  Inheritance  
File Role Description
  Plain text file AnimalServiceTest.php Class Class source

  Files folder image Files  /  tests  /  AppBundle  /  Service  /  InterfaceImplementation  
File Role Description
  Plain text file AnimalServiceTest.php Class Class source

  Files folder image Files  /  var  
File Role Description
  Plain text file SymfonyRequirements.php Class Class source

  Files folder image Files  /  web  
File Role Description
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login Plain text file app.php Example Example script
  Accessible without login Image file apple-touch-icon.png Icon Icon image
  Accessible without login Plain text file app_dev.php Example Example script
  Accessible without login Plain text file config.php Example Example script
  Accessible without login Image file favicon.ico Data Auxiliary data
  Accessible without login Plain text file robots.txt Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:63
This week:0
All time:9,785
This week:199Up

For more information send a message to info at phpclasses dot org.