The document discusses the SOLID principles of object-oriented design:
- Single Responsibility Principle (SRP): A class should have one, and only one, reason to change. Symptoms include a class with multiple responsibilities or dependencies.
- Open Closed Principle (OCP): A class should be open for extension but closed for modification. New functionality should not require changing existing code.
- Liskov Substitution Principle (LSP): Derived classes must be substitutable for their base classes.
- Interface Segregation Principle (ISP): Interfaces should be specific to the client and not contain methods that the client doesn't use.
- Dependency Inversion Pr
15. Single Responsibility Principle
Open Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
16. – Uncle Bob
„OOP is about managing dependency by
selectively inverted some key dependencies in
your architecture to prevent rigidity, fragility, not
reusability“
24. Symptomy
• účel třídy nejde pospat bez spojek a, nebo
• třída obsahuje velké množství properties a
public method
• třída obsahuje velké množství závislostí na další
objekty
35. function getReport($type, $employee)
{
switch ($type):
case 'xml'
return $this->xmlReportBuilder->getReport($employee);
case 'json'
return $this->jsonReportBuilder->getReport($employee);
default:
throw new IllegalArgumentException();
}
36. function getReport($type, $employee)
{
switch ($type):
case 'xml'
return $this->xmlReportBuilder->getReport($employee);
case 'json'
return $this->jsonReportBuilder->getReport($employee);
default:
throw new IllegalArgumentException();
} OCP
42. class Square
{
public function setHeight($height)
{
$this->height = $height;
parent::setWidth($height);
}
public function setWidth($width)
{
$this->width = $width;
parent::setHeight($width);
}
}
46. class Rectangle
{
public function getHeight() {}
public function getWidth() {}
public function setHeight() {}
public function setWidth() {}
}
class Square
{
public function getSize() {}
public function setSize() {}
}