This repository contains some classes that are needed for an experiment one of my projects is currently involved in.
This experiment consists of three separate concepts
- There should only be one single point where objects are created
- Classes in a project should only extend a 'base' class
- Any class should only contain Data, Logic or Decisions.
Yes, I know madness. No, I don't expect you do take this seriously or follow my lead. It's just to satisfy my own curiosity. That is why it is called an "experiment".
Just as a class method should only contain one single return statement, or a
project should only contain one single echo
statement (these are from other
experiments I did a while ago), there should only be one single point where
objects are created. This should either be a single delivery mechanism file,
(like the well-known index.php
), a factory, or a "service locator".
The locator is a last resort and only acceptable as long as the locator is kept out of the rest of the project. The service locator pattern really is an anti-pattern as far as it makes everything in your project very tightly coupled to anything the locator might contain (even is it is just semantically).
All classes in this experiment should extend the Project
class or a class
that extends that class. This way there is absolutely no chance of any vendor
or native PHP classes being extended.
This allows us to add a check to the build to enforce the Composition over Inheritance "rule".
The Project
class itself explicitly extends the native PHP class, to make sure
there is no cheating this rule.
Classes should also have a strict separation between condition (Decision), information (Data) and function (Logic). To enforce this there are three (empty) abstract classes for project classes to extend. These classes make it explicitly clear what they expect child classes to contain.
Data should be moved to a class extending the Data
class
Decisions should be moved to a class extending the Decision
class.
Logic should be moved to a class extending the Logic
class.
When a class has method(s) that break this rule, offending functions should be moved to another class that is a better fit. If such a class does not exist it will have to be written.
Extending classes may contain logic which can be applied to data as determined by Decision classes. Extending classes may not, themselves, make Decisions or contain Data.
Extending classes may contain data that can be passed to Logic classes as determined by Decision classes. Extending classes may not, themselves, make Decisions or contain Logic.
Extending classes may make a Decision about which Logic should be applied to which Data. Extending classes may not, themselves, contain Data or Logic.
0.1.1 – The Source Code for this project is available on github.com under a GPLv3 License – Created by Potherca