Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's a good implementation but it can be finetuned a bit if you use interfaces.</p> <p>An abtract class with all virtual methods it's just a interface so don't use abstract classes, use <a href="http://php.net/manual/en/language.oop5.interfaces.php" rel="noreferrer">interfaces</a>.</p> <pre><code>interface IDataFileFactory{ public function createFile($id); } class FileAFactory implements IDataFileFactory class FileBFactory implements IDataFileFactory </code></pre> <p>If you find repeating code in <code>FileAFactory</code> and in <code>FileBFactory</code> methods then it is time to refactor your classes and create inheritance.</p> <pre><code>interface IDataFileFactory{ public function createFile($id); } abstract class BaseFileFactory implements IDataFileFactory { //some methods implementation with common features to avoid repeating code //some abstract methods to be implemented for A and B FileFactories //absolute abstract base class has no sense because in php you can use interfaces. //... } class FileAFactory extends BaseFileFactory class FileBFactory extends BaseFileFactory </code></pre> <p>Then use throug interface:</p> <pre><code> public function readFiles(IDataFileFactory $factory){ //create a file using factory return IDataFile; //return Interface implemented by all DataFile types. } </code></pre> <p>You can do the same thing with <code>DataFile</code> base class and so on.</p> <p>I also recomend to not pass factories in parameters because a factory is out of context. Try to do not mix architecture implementation with data and info process workflow. You can create a container, in a scope accesible for your other classes, to resolve the factory.</p> <p>The container can, for example, read configuration files to create concrete factory in application bootstrap; read from some value, choosed by the user in previous steps of the user case, stored in a class instance or accepting a parameter in runtime to resolve the factory. It's about implement some kind of simple dependency inyection.</p> <p>Anyway, this is only my point of view and can be a hurge amount disagreements.</p> <p>I hope it help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload