solid and symfony. desymfonyday 2014
DESCRIPTION
SOLID and Symfony. My talk in the deSymfony 2014 conference in BarcelonaTRANSCRIPT
![Page 1: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/1.jpg)
![Page 2: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/2.jpg)
![Page 3: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/3.jpg)
¿QUE SOMOS?
![Page 4: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/4.jpg)
¿QUIÉN SOY YO?
![Page 5: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/5.jpg)
¿QUIÉN SOY YO?Gonzalo Ayuso
@gonzalo123http://gonzalo123.comhttps://github.com/gonzalo123
![Page 6: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/6.jpg)
¿QUIÉN SOY YO?Gonzalo Ayuso
@gonzalo123http://gonzalo123.comhttps://github.com/gonzalo123
![Page 7: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/7.jpg)
katayunos.com
¿QUIÉN SOY YO?Gonzalo Ayuso
@gonzalo123http://gonzalo123.comhttps://github.com/gonzalo123
![Page 8: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/8.jpg)
¿QUE SOMOS?
![Page 9: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/9.jpg)
¿QUE SOMOS?Pogramadores
![Page 10: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/10.jpg)
¿QUE SOMOS?Pogramadores
¿A QUÉ DEDICAMOS NUESTRO TIEMPO?
![Page 11: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/11.jpg)
¿QUE SOMOS?Pogramadores
¿A QUÉ DEDICAMOS NUESTRO TIEMPO?A programar
![Page 12: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/12.jpg)
¿QUE SOMOS?Pogramadores
¿A QUÉ DEDICAMOS NUESTRO TIEMPO?A programar
![Page 13: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/13.jpg)
¿QUE SOMOS?Pogramadores
¿A QUÉ DEDICAMOS NUESTRO TIEMPO?A programarA leer
![Page 14: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/14.jpg)
¿QUE SOMOS?Pogramadores
¿A QUÉ DEDICAMOS NUESTRO TIEMPO?A programarA leer
![Page 15: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/15.jpg)
$this->createUser(true);
![Page 16: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/16.jpg)
$this->createUser(true);¿?¿?¿?
![Page 17: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/17.jpg)
S.O.L.I.D.
![Page 18: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/18.jpg)
S.O.L.I.D.ROBERT. C. MARTIN (THE CLEAN CODE)
Single responsibility, Open-closed, Liskov substitution, Interface segregation,Dependency inversion
![Page 19: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/19.jpg)
SRP - SINGLE RESPONSIBILITY PRINCIPLEPRINCIPIO DE RESPONSABILIDAD ÚNICA
![Page 20: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/20.jpg)
SRP - SINGLE RESPONSIBILITY PRINCIPLEPRINCIPIO DE RESPONSABILIDAD ÚNICA
CADA COMPONENTE => UNA RESPONSABILIDAD
![Page 21: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/21.jpg)
SRP - SINGLE RESPONSIBILITY PRINCIPLEPRINCIPIO DE RESPONSABILIDAD ÚNICA
CADA COMPONENTE => UNA RESPONSABILIDAD
UNA RESPONSABILIDAD = UNA RAZÓN DE CAMBIO
![Page 22: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/22.jpg)
SRP - SINGLE RESPONSIBILITY PRINCIPLEPRINCIPIO DE RESPONSABILIDAD ÚNICA
CADA COMPONENTE => UNA RESPONSABILIDAD
UNA RESPONSABILIDAD = UNA RAZÓN DE CAMBIO
CADA COMPONENTE => UNA ÚNICA RAZÓN PARA CAMBIAR
![Page 23: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/23.jpg)
OCP - OPEN/CLOSED PRINCIPLEPRINCIPIO DE ABIERTO/CERRADO
![Page 24: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/24.jpg)
OCP - OPEN/CLOSED PRINCIPLEPRINCIPIO DE ABIERTO/CERRADO
LAS ENTIDADES DE SOFTWARE DEBEN SER ABIERTAS PARA EXTENDER, PERO CERRADAS PARA MODIFICACIÓN
![Page 25: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/25.jpg)
OCP - OPEN/CLOSED PRINCIPLEPRINCIPIO DE ABIERTO/CERRADO
LAS ENTIDADES DE SOFTWARE DEBEN SER ABIERTAS PARA EXTENDER, PERO CERRADAS PARA MODIFICACIÓN
HTTPKernel
http://stackphp.com
![Page 26: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/26.jpg)
OCP - OPEN/CLOSED PRINCIPLEPRINCIPIO DE ABIERTO/CERRADO
LAS ENTIDADES DE SOFTWARE DEBEN SER ABIERTAS PARA EXTENDER, PERO CERRADAS PARA MODIFICACIÓN
<?phpuse Symfony\Component\EventDispatcher\EventDispatcher;$dispatcher = new EventDispatcher();
$listener = new AcmeListener();$dispatcher->addListener('action', array($listener, 'onFooAction'));
Event Dispatcher (Patrón Mediator)
![Page 27: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/27.jpg)
LSP -LISKOV SUBSTITUTION PRINCIPLEPRINCIPIO DE SUBSTITUCIÓN DE LISKOV
![Page 28: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/28.jpg)
LSP -LISKOV SUBSTITUTION PRINCIPLEPRINCIPIO DE SUBSTITUCIÓN DE LISKOV
DEBE SER POSIBLE UTILIZAR CUALQUIER OBJETO INSTANCIA DE UNA SUBCLASE EN LUGAR
DE CUALQUIER OBJETO INSTANCIA DE SU SUPERCLASE SIN QUE LA SEMÁNTICA DEL
PROGRAMA ESCRITO EN LOS TÉRMINOS DE LA SUPERCLASE SE VEA AFECTADO.
![Page 29: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/29.jpg)
LSP -LISKOV SUBSTITUTION PRINCIPLEPRINCIPIO DE SUBSTITUCIÓN DE LISKOV
DEBE SER POSIBLE UTILIZAR CUALQUIER OBJETO INSTANCIA DE UNA SUBCLASE EN LUGAR
DE CUALQUIER OBJETO INSTANCIA DE SU SUPERCLASE SIN QUE LA SEMÁNTICA DEL
PROGRAMA ESCRITO EN LOS TÉRMINOS DE LA SUPERCLASE SE VEA AFECTADO.SI S ES UN SUBTIPO DE T, ENTONCES LOS OBJETOS DE TIPO T PUEDEN SER
REEMPLAZADOS POR LOS OBJETOS DE TIPO S.
![Page 30: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/30.jpg)
LSP -LISKOV SUBSTITUTION PRINCIPLEPRINCIPIO DE SUBSTITUCIÓN DE LISKOV
CADA CLASE QUE HEREDA DE OTRA PUEDE USARSE COMO SU PADRE SIN NECESIDAD DE CONOCER LAS DIFERENCIAS ENTRE
ELLAS.
![Page 31: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/31.jpg)
LSP -LISKOV SUBSTITUTION PRINCIPLEPRINCIPIO DE SUBSTITUCIÓN DE LISKOV
class Application extends Container
implements HttpKernelInterface, TerminableInterface
{}
CADA CLASE QUE HEREDA DE OTRA PUEDE USARSE COMO SU PADRE SIN NECESIDAD DE CONOCER LAS DIFERENCIAS ENTRE
ELLAS.
Silex\Application
![Page 32: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/32.jpg)
LSP -LISKOV SUBSTITUTION PRINCIPLEPRINCIPIO DE SUBSTITUCIÓN DE LISKOV
class Application extends Container implements HttpKernelInterface, TerminableInterface{}
Silex\Application
use Silex\Application;
$app = new Application();
![Page 33: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/33.jpg)
LSP -LISKOV SUBSTITUTION PRINCIPLEPRINCIPIO DE SUBSTITUCIÓN DE LISKOV
class Application extends Container implements HttpKernelInterface, TerminableInterface{}
Silex\Application
use Silex\Application;
$app = new Application();
Silex\Application
Pimple\Container
![Page 34: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/34.jpg)
ISP - INTERFACE SEGREGATION PRINCIPLEPRINCIPIO DE SEGREGACIÓN DE INTERFACES
![Page 35: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/35.jpg)
ISP - INTERFACE SEGREGATION PRINCIPLEPRINCIPIO DE SEGREGACIÓN DE INTERFACES
MUCHAS INTERFACES ESPECÍFICAS SON MEJORES QUE UNA INTERFAZ DE PROPÓSITO GENERAL.
![Page 36: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/36.jpg)
ISP - INTERFACE SEGREGATION PRINCIPLEPRINCIPIO DE SEGREGACIÓN DE INTERFACES
interface StreamIface
{
public function open();
public function read();
public function write();
}
![Page 37: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/37.jpg)
ISP - INTERFACE SEGREGATION PRINCIPLEPRINCIPIO DE SEGREGACIÓN DE INTERFACES
interface StreamIface
{
public function open();
public function read();
public function write();
}
class File implements StreamIface
![Page 38: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/38.jpg)
ISP - INTERFACE SEGREGATION PRINCIPLEPRINCIPIO DE SEGREGACIÓN DE INTERFACES
interface StreamIface
{
public function open();
public function read();
public function write();
}
class File implements StreamIface
class ReadOnlyFile implements StreamIface
?
![Page 39: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/39.jpg)
ISP - INTERFACE SEGREGATION PRINCIPLEPRINCIPIO DE SEGREGACIÓN DE INTERFACES
interface ReadableStreamIface{ public function open(); public function read();}interface WritableStreamIface{ public function write();}
class ReadOnlyFile implements ReadableStreamIface
class File implements ReadableStreamIface, WritableStreamIface
![Page 40: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/40.jpg)
ISP - INTERFACE SEGREGATION PRINCIPLEPRINCIPIO DE SEGREGACIÓN DE INTERFACES
class Application extends Container
implements HttpKernelInterface, TerminableInterface
{...}
Silex\Application
use Silex\Application;
$app = new Application();
TerminableInterface
HttpKernelInterface
![Page 41: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/41.jpg)
DIP - DEPENDENCY INVERSION PRINCIPLEPRINCIPIO DE INVERSIÓN DE DEPENDENCIAS
LAS ABSTRACCIONES NO DEBERÍAN DEPENDER DE DETALLES SINO QUE LOS DETALLES
DEBERÍAN DEPENDER DE LAS ABSTRACCIONES.
![Page 42: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/42.jpg)
LAS ABSTRACCIONES NO DEBERÍAN DEPENDER DE DETALLES SINO QUE LOS DETALLES
DEBERÍAN DEPENDER DE LAS ABSTRACCIONES.
LOS MÓDULOS DE ALTO NIVEL NO DEBERÍAN DEPENDER DE MÓDULOS DE BAJO NIVEL,
AMBOS DEBERÍAN DEPENDER DE ABSTRACCIONES.
DIP - DEPENDENCY INVERSION PRINCIPLEPRINCIPIO DE INVERSIÓN DE DEPENDENCIAS
![Page 43: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/43.jpg)
class ChickenPizza extends BasePizza{ private $ingredients;
public function __construct() { $this->ingredients[] = new Chicken(); $this->ingredients[] = new Cheese(); $this->ingredients[] = new Fruit(); }}
$chickenPizza = new ChickenPizza();$chickenPizza->make();
DIP - DEPENDENCY INVERSION PRINCIPLEPRINCIPIO DE INVERSIÓN DE DEPENDENCIAS
![Page 44: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/44.jpg)
$chickenPizza = new Pizza();$chickenPizza->appendIngredient(new Chicken());$chickenPizza->appendIngredient(new Cheese());$chickenPizza->appendIngredient(new Fruit());$chickenPizza->make();
DIP - DEPENDENCY INVERSION PRINCIPLEPRINCIPIO DE INVERSIÓN DE DEPENDENCIAS
![Page 45: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/45.jpg)
class Pizza implements IngredientStackIface{ private $ingredients; public function appendIngredient(Ingredient $ingredient) { $this->ingredients[] = $ingredient; } public function make() { }}
DIP - DEPENDENCY INVERSION PRINCIPLEPRINCIPIO DE INVERSIÓN DE DEPENDENCIAS
![Page 46: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/46.jpg)
use Symfony\Component\Config\FileLocator;
$chickenPizza = new Pizza();$locator = new FileLocator(__DIR__);$loader = new YamlFileLoader($chickenPizza, $locator);$loader->load('config.yml');
$chickenPizza->make();
Config component: http://blog.servergrove.com/2014/02/21/symfony2-components-overview-config/
DIP - DEPENDENCY INVERSION PRINCIPLEPRINCIPIO DE INVERSIÓN DE DEPENDENCIAS
![Page 47: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/47.jpg)
SI PERO, ¿MERECE LA PENA TODO ESTO?
![Page 48: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/48.jpg)
SI PERO, ¿MERECE LA PENA TODO ESTO?
TODO ESTO SE HACE POR ...
![Page 49: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/49.jpg)
SI PERO, ¿MERECE LA PENA TODO ESTO?
TODO ESTO SE HACE POR ...
€
![Page 50: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/50.jpg)
SI PERO, ¿MERECE LA PENA TODO ESTO?
EFICIENCIA VS MANTENIMIENTO
TODO ESTO SE HACE POR ...
€
![Page 51: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/51.jpg)
SI PERO, ¿MERECE LA PENA TODO ESTO?
EFICIENCIA VS MANTENIMIENTO
TODO ESTO SE HACE POR ...
€
SYMFONY -> SOLID PERO Y NUESTRA APP?
![Page 52: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/52.jpg)
PROGRAMAR ES FÁCIL. PROGRAMAR BIEN ES MUY COMPLICADO.
![Page 53: SOLID and Symfony. deSymfonyDay 2014](https://reader033.vdocuments.co/reader033/viewer/2022050904/548113f8b479593c578b4817/html5/thumbnails/53.jpg)
GRACIAS / ESKERRIK ASKO&
BE SOLID MY FRIEND!
¿PREGUNTAS? ¿APLAUSOS? :)
Gonzalo Ayuso@gonzalo123http://gonzalo123.comhttps://github.com/gonzalo123