Solid Principles
&
Design Patterns
with PHP examples
FEDERICO LOZADA MOSTO
Facebook: @mostofreddy
Linkedin: ar.linkedin.com/in/federicolozadamosto
Github: @mostofreddy
Instagram: @mostofreddy
✓ Introduction to OOP
✓ SOLID principles
✓ Gof Patterns
✓ Other patterns
Topics
OOPObject Oriented Programming
✓ Class
✓ Object
✓ Instance
✓ Polymorphism
✓ Hierarchy
✓ Coupling & Cohesion
Concepts
✓ Encapsulation
✓ Attributes & methods
✓ Messages
✓ Interface
✓ Accessors (protected, private, public)
✓ Composition
SOLIDPrinciples
S
O
L
I
D
Open/Closed Principle
Single Responsibility Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion
S Single Responsibility Principle
A class should have one and only one reason to
change, meaning that a class should have only
one job.
“
Single Responsibility Principle !
Single Responsibility Principle !
Single Responsibility Principle :)
Single Responsibility Principle :)
O Open/Closed Principle
“Objects or entities should be open for extension,
but closed for modification.
Open / Close Principle !
Open / Close Principle :)
L Liskov Substitution Principle
Let q(x) be a property provable about objects of
x of type T. Then q(y) should be provable for
objects y of type S where S is a subtype of T.“
Liskov Substitution Principle :)
I Interface Segregation Principle
A client should never be forced to implement an
interface that it doesn't use or clients shouldn't
be forced to depend on methods they do not
use
“
Interface Segregation Principle :)
D 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
“
Patterns
GoF Patterns
The Gang of Four
GoF Patterns
✓ Creational
provide ways to instantiate single objects or groups of related objects
✓ Structural
provide a manner to define relationships between classes or objects
✓ Behavioural
define manners of communication between classes and objects
Abstract Factory | creational
Factory Method | creational
Factory Method | creational
Factory Method | creational
Builder | creational
Builder | creational
Builder | creational
Builder | creational
Builder | creational
Singleton | creational
Singleton | creational
Adapter | structural
Adapter | structural
Adapter | structural
Adapter | structural
Decorator | structural
Decorator | structural
Decorator | structural
Decorator | structural
Decorator | structural
Facade | structural
Facade | structural
Facade | structural
Command | Behavioral
Command | Behavioral
Command | Behavioral
Iterator | Behavioral
Iterator | Behavioral
Iterator | Behavioral
Strategy | Behavioral
Strategy | Behavioral
Strategy | Behavioral
Null Object | Behavioral
Null Object | Behavioral
More Patterns
MVC | ….
Active Record | persistence
Repository | persistence
Service Locator | Inversion of control
Service Locator | Inversion of control
Service Locator | Inversion of control
Dependency Injection | Inversion of control
Dependency Injection | Inversion of control
Dependency Injection | Inversion of control
Pipeline
Pipeline
Middleware
Middleware
Middleware
Questions?
Thanks!
Thanks!
FEDERICO LOZADA MOSTO
FB: mostofreddy
In: ar.linkedin.com/in/federicolozadamosto
Git: mostofreddy
Ig: mostofreddy
{
"require": {
"php": ">=5.5.0",
"ext-gd": "*",
"lib-curl": "*"
}
}
Iconos
PHP extension
& libraries
libraries available:
curl, iconv, libxml, openssl, pcre, uuid, xsl
Tip: composer show --platform
!
!

Solid Principles & Design patterns with PHP examples