Design Patterns Flashcards
What is a design pattern?
Provide general reusable solutions to one type of problems during software development, they provide an architecture.
Why would you use a design pattern?
Avoids reinventing the wheel, reuses designs and solutions that have proved useful in the past by experienced object-oriented designers.
What are the types of design patterns?
Creational Patterns
Structural Patterns
Behavioral Patterns
What are creational patterns?
Abstraction of instantiation process.
What are structural patterns?
Composition of classes and objects.
What are behavioral patterns?
Interaction between objects.
What does the Factory Pattern do?
Defines an interface for creating an object, but lets subclasses decide which class to instantiate. It lets a class defer instantiation to subclasses. (uses abstract class PizzaShop)
What is the Abstract Factory Pattern?
Provides an interface for creating families of related dependent objects without specifying their concrete classes. (uses interface PizzaIngredientFactory which the concrete subclasses implement)
What is the Builder Pattern?
Separates the construction of a complex object from its representation so that the same construction processes can create different representations.
Allows you to vary a products internal representation
Isolates code for construction and representation
Finer control over the construction process
In the Builder Pattern how does the Builder work?
The builder specifies the interface for creating parts of the complex (product) object.
In the Builder Pattern how does the ConcreteBuilder work?
The concrete builder objects create and assemble the parts that make up the product through the builder interface.
In the Builder Pattern how does the Director work?
The director object takes responsibility for the construction process of the complex (Product) object, however it delegates the actual creation and assembly to the Builder interface.
In the Builder Pattern how does the Product work?
The product represents the complex object that is created by the concretebuilder object. The product consists of multiple parts that are created separately by the concrete builder objects.
Builder pattern pseudocode
TopLevelClass creates specific pizza builder creates director (waiter) waiter.setPizzaBuilder(pizza builder) waiter.constructPizza waiter.getPizza.
Benefits of the builder pattern
Encapsulates the way a complex object is constructed
Allows objects to be constructed in a multistep and varying process
Hides the internal representation of the product from the client.