Creational Design Patterns Flashcards

1
Q

What is definition of Factory Method?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Does the Factory Method need to create new objects all the time?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Provide Abstract Factory definition

A

Design pattern that lets you
produce families of related objects without specifying their
concrete classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Provide Builder design pattern definition

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Provide Prototype design pattern definition

A

Design pattern that lets you copy
existing objects without making your code dependent on
their classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Provide Singleton design pattern definition

A

Design pattern that lets you ensure
that a class has only one instance, while providing a global
access point to this instance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which SOLID rule violates Singleton pattern

A

Single Responsibility Principle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the role of Director in Builder pattern?

A

The director optional class which defines the order in which to execute the building steps, while the builder provides the implementation for those steps

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Does products constructed by different builders under the same interface don’t have to belong to the same class hierarchy or interface?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Where should be declared method for retrieveing object builded by the Builder?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to retrive builded object (code example) in case of using Directior class?

A

director = new Director()
CarBuilder builder = new CarBuilder() director.constructSportsCar(builder)
Car car = builder.getProduct()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly