created, $=dv.current().file.ctime & modified, =this.modified

  • Single-responsibility
  • Open-closed
  • Liskov-substitution
  • Interface segregation
  • Dependency inversion

Single-responsibility

A class should have one and only one reason to change, meaning a class should have only one job.

$shapes = [
	new circle[2],
	new square[2],
	new square[6]
]

// rather than combine output types in Area Calculator, we decompose and form SumCalculatorOutputter
$areas = new AreaCalculator($shapes);
$output = new SumCalculatorOutputter($areas);
echo $output->JSON();
echo $output->HTML();

Open-closed

Objects or entities should be open for extension but closed for modification

A class should be extendable without modifying the class itself.

interface ShapeInterface {
	public function area();
}

class circle implements ShapeInterface {
	...
}

Liskov-substitution

Let q(x) be a property provable about object x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T

Every subclass or derived class should be substitutable for their base or parent class.

Interface Segregation

A client should never be forced to implement an interface that it doesn’t use or client shouldn’t be forced to depend on methods they don’t use.

class cuboid implements ShapeInterface, ThreeDimensionalShapeInterface, ManageShapeInterface

Dependency Inversion

Entities must depend on abstractions, not on concretions. It states that the high-level module must not depend on the low-level module, but they should depend on abstractions.

Decoupling.

class MySQLConnection
{
    public function connect()
    {
        // handle the database connection
        return 'Database connection';
    }
}

class PasswordReminder
{
    private $dbConnection;

    public function __construct(MySQLConnection $dbConnection)
    {
        $this->dbConnection = $dbConnection;
    }
}
class MySQLConnection implements DBConnectionInterface
{
    public function connect()
    {
        // handle the database connection
        return 'Database connection';
    }
}

class PasswordReminder
{
    private $dbConnection;

    public function __construct(DBConnectionInterface $dbConnection)
    {
        $this->dbConnection = $dbConnection;
    }
}
```