Design patterns

21
Design Patterns PHP

Transcript of Design patterns

Page 1: Design patterns

Design PatternsPHP

Page 2: Design patterns

Un design pattern o patrón de diseño es una solución

reutilizable frente a problemas frecuentes en el

diseño de software.

Design Patterns

Page 3: Design patterns

¿Por qué utilizarlos?

Acelera el desarrollo

Soluciones probadas frente a paradigmas de desarrollo

Mejora la legibilidad del código

Page 4: Design patterns

Factory method

El factory pattern es una clase que tiene una sierie de methods que permiten

crear objetos.

Page 5: Design patterns
Page 6: Design patterns
Page 7: Design patterns
Page 8: Design patterns
Page 9: Design patterns
Page 10: Design patterns

Command

Un objeto es utilizado para representar y encapsular todo la información necesaria para

llamar luego a un method. Esta información incluye el method name, el objeto dueño del

method y los valores los parámetros del method.

Page 11: Design patterns
Page 12: Design patterns
Page 13: Design patterns

Cadena de responsabilidades

Avoid coupling the sender of a request to its receiver by giving more than one object a

chance to handle a request. Chain the receiving objects and pass the request along the chain

until an object handles it.A mechanism also exists for adding new

processing objects to the end of this chain.

Variación: árbol de responsabilidad..

Page 14: Design patterns
Page 15: Design patterns

This pattern shares some structural similarities with Java exceptions: either they are handled or passed on.

This pattern is useful for hierarchical structures where a request can be handled at multiple layers.

Like our GUI event handling is done hierarchically. If an object doesn't want to handle an event it can delegate it to its parent, up the chain.

Page 16: Design patterns

Decorator

Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending

functionality

The original code is open to extension but closed to modification

“Open/closed principle”

Page 17: Design patterns
Page 18: Design patterns

CompositeThe composite pattern describes that a group of objects are to be treated in the same way as a

single instance of an object.Compose objects into tree structures to

represent part-whole hierarchies. Composite lets clients treat individual objects and

compositions of objects uniformly.

Page 19: Design patterns
Page 20: Design patterns

State

Allow an object to alter its behavior when its internal state changes.

The object will appear to change its class.

Page 21: Design patterns