PHP Classes

PHP Polymorphism Example: Show several ways of implementing of polymorphism

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 69 All time: 10,304 This week: 560Up
Version License PHP version Categories
polymorphism 1.0.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: 9 packages by
Country: Spain Spain
Age: 42
All time rank: 306478 in Spain Spain
Week rank: 47 Up3 in Spain Spain Up
Innovation award
Innovation award
Nominee: 6x

Winner: 1x

Documentation

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 (61)  
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 (61)  /  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 (61)  /  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 (61)  /  app  /  Resources  
File Role Description
Files folder imageviews (1 file, 1 directory)

  Files folder image Files (61)  /  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 (61)  /  app  /  Resources  /  views  /  default  
File Role Description
  Accessible without login Plain text file index.html.twig Data Auxiliary data

  Files folder image Files (61)  /  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 (61)  /  docs  
File Role Description
  Accessible without login Plain text file polimorfismo.md Data Auxiliary data

  Files folder image Files (61)  /  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 (61)  /  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 (61)  /  src  /  AppBundle  /  Controller  
File Role Description
  Plain text file DefaultController.php Class Class source

  Files folder image Files (61)  /  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 (61)  /  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 (61)  /  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 (61)  /  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 (61)  /  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 (61)  /  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 (61)  /  src  /  AppBundle  /  Service  /  AbstractInheritance  
File Role Description
  Plain text file AnimalService.php Class Class source

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

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

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

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

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

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

  Files folder image Files (61)  /  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 (61)  /  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 (61)  /  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 (61)  /  tests  /  AppBundle  /  Service  /  AbstractInheritance  
File Role Description
  Plain text file AnimalServiceTest.php Class Class source

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

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

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

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

  Files folder image Files (61)  /  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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:69
This week:0
All time:10,304
This week:560Up