Patrones Flashcards
Types of Design Patterns
Creational, structural and behavioural
Elements of the Builder Pattern
- Builder interface which defines building steps
- Concrete builders that implement the interface and can return a result
- Director which contains a classes and runs the build steps (without returning the result)
Elements of the Factory Pattern
- Factory interface
- Concrete factories which implement the interface
Example of Factory Pattern
An abstract factory for a monster class, and three concrete factories according to the difficulty of the generated monsters
Elements of an Abstract Factory pattern
- An AbstractFactory interface
- Concrete factories that inherit from the AbstractFactory
Example of Abstract Factory pattern
In a game, factories of different monsters, with different difficulties
Or UI component factories, where there are two factories, one for Windows and one for macOS, each capable of creating different types of componentes.
Elements of the (Object) Adapter Pattern
- A Client Interface that is understood by the Client
- An Adapter that inherits from the desired Client Interface, implementing it while wrapping a service
Elements of the Composite Pattern
- An interface component for the Client to consume
- A Leaf basic node, that inherits from the Interface. (This is the minimal object)
- A Container (Composite) that is composed by leaves or other containers. It interacts with it’s children via the Interface
Elements of the Decorator Pattern
- A Base Decorator, which envelops a class and emulates its interface, that the Client Consumes
- Concrete decorators that inherit from the Base Decorator
Elements of the Observer pattern
- A Publisher class which has a list of subscribers, and has methods for subscribing, unsubscribing and notifying its subscribers
- A Subscriber interface to receive updates
- Concrete Subscribers which do things when they receive an update
Elements of the Facade Pattern
- A Facade, which is a class that deals with a lot of Subsystem classes, and simplifies the system complexity
- Additional Facades can be created for other operations
Elements of the Command pattern
- A Command interface, which describes methods to execute commands
- Concrete commands that do something when their execute methods are called
- A client that creates and configures the commands
- Invokers or Senders which can store and run commands.
- (Optionally) a Receiver which does the actual business logic behind a command
Elements of a Strategy pattern
- A Context which can store a strategy, change their strategy using a method and do something using the strategy.
- A strategy interface
- Concrete strategies implementing the interface
Ruby method equivalent of __init__
def initialize(args)...end
Para exponer atributos en Ruby, es necesario usar…
attr_accesor, attr_reader o attr_writer para crear getters y setters, o implementarlos a mano