Creational Design Patterns Flashcards
What is definition of Factory Method?
Design pattern that provides
an interface for creating objects in a superclass, but allows
subclasses to alter the type of objects that will be created
Does the Factory Method need to create new objects all the time?
Factory method doesn’t have to create new instances all the time. It can also return existing objects from
a cache, an object pool, or another source
Provide Abstract Factory definition
Design pattern that lets you
produce families of related objects without specifying their
concrete classes
Provide Builder design pattern definition
Design pattern that lets you construct
complex objects step by step. The pattern allows you to
produce different types and representations of an object using
the same construction code
Provide Prototype design pattern definition
Design pattern that lets you copy
existing objects without making your code dependent on
their classes
Provide Singleton design pattern definition
Design pattern that lets you ensure
that a class has only one instance, while providing a global
access point to this instance
Which SOLID rule violates Singleton pattern
Single Responsibility Principle
What is the role of Director in Builder pattern?
The director optional class which defines the order in which to execute the building steps, while the builder provides the implementation for those steps
Does products constructed by different builders under the same interface don’t have to belong to the same class hierarchy or interface?
Yes
Where should be declared method for retrieveing object builded by the Builder?
In concrete builders not in the common interface. That’s because various types of builders may create entirely different products that don’t all follow the same interface. Therefore such methods can’t be declared in the builder interface (at least not in a statically-typed programming language).
How to retrive builded object (code example) in case of using Directior class?
director = new Director()
CarBuilder builder = new CarBuilder() director.constructSportsCar(builder)
Car car = builder.getProduct()