Answer the question
In order to leave comments, you need to log in
How does polymorphism work in php through abstract classes and abstract methods?
There is a set of doctrine entities and there is a code that should do something with these entities.
Because there will be a lot of entities and ways to use entities, then I want to designate basic methods in abstract classes.
<?php
namespace App\Entity;
abstract class AbstractEntity;
{
//...
}
<?php
namespace App\AnotherName;
use App\Entity\AbstractEntity;
abstract class AbstractService
{
abstract public function create(AbstractEntity $entity);
}
<?php
namespace App\Entity;
class AnotherEntity extend AbstractEntity;
{
//...
}
<?php
namespace App\Service\AnotherName;
use App\Entity\AnotherEntity;
class FooService extend AbstractService
{
public function create(AnotherEntity $anotherEntity) {
//...
}
}
<?php
namespace App\Service\AnotherName;
use App\Entity\AbstractEntity;
class FooService extend AbstractService
{
public function create(AbstractEntity $anotherEntity) {
//...
}
}
Answer the question
In order to leave comments, you need to log in
through interfaces: `function setFoo(FooInterface $instance)`, the interface describes methods, abstract classes - the basic implementation of these methods, for example, the implementation of the template adapter on the example of the database: DBMS adapter interface, abstract adapter for mysql implementing interface, class extending mysql abstract adapter php based mysql extension + class extending abstract mysql adapter based on php mysql extension i
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question