Gof Flashcards

1
Q

Which pattern restricts the initialization of a class to ensure that only one instance of the class can be created?

A

Singleton

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

Which pattern takes out the responsibility of instantiating a object from the class to a new class with only this responsibility?

A

Factory

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

Which pattern create a Factory for factory classes?

A

Abstract Factory

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

Which creates an object step by step and a method to finally get the object instance?

A

Builder

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

Which pattern creates a new object instance from another similar instance and then modify according to our requirements?

A

Prototype

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

Which pattern creates an interface so that two distinct interfaces can work together?

A

Adapter

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

Which pattern creates an interface with multiple pieces or leaves in a part-whole?

A

Composite (FileSystemItem -> File, Directory that contains files)

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

Which pattern creates a new object that controls an object?

A

Proxy (Functionality -> AdminFunctionality)

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

Which pattern caches objects so that they do not need to be instantiated again for the same functionality?

A

Flyweight

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

Which pattern creates an interface so that it lowers complexity of its parts?

A

Facade (SoundSystem, TvSystem -> HomeTheaterFacade)

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

Which pattern creates an abstraction so that both implementations and interfaces can grow separately?

A

Bridge
abstract vehicle - bus,bike
interface WorkShop - produce, assemble)

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

Which pattern creates an abstract class that defines the skeleton and passes the responsibility of implementing some steps to the subclasses?

A

Template
(Abstract BuildHouse -> GlassHouse, WoodenHouse)

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

Which pattern abstract communications between objects, decoupling them into a single interface?

A

Mediator

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

Which pattern decouples client requests that follow a order so that each step is not coupled?

A

Chain of responsibility
(ATM dispenser with 50DollarDispense, 20DollarDispense, etc)

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

Which pattern makes objects be notified of changes made to their interested objects?

A

Observer
interface Observer -> class YtSubscriber
interface Subject -> class YtChannel

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

Which pattern enables multiple implementations to be selected at runtime?

A

Strategy
interface PaymentStrategy -> CreditCard, Cash

17
Q

Which pattern decouples the sender of the request from the receiver?

A

Command
interface Command -> class TurnLightOnCommand

18
Q

Which pattern decouples if-else implentations to be applyed when the object internal memory is changed?

A

State
interface TvState -> OnState, OffState
doAction now would do different things depending on the internal state

19
Q

Which pattern decouples implementations from classes that are similar, without ever changing the original classes?

A

Visitor
interface FruitColorVisitor
visitBanana
visitApple
interface FruitPriceVisitor
visitBanana
visitApple

20
Q

Which defines a grammatical representation for a language and provides an interpreter to deal with this grammar?

A

Interpreter
Calculator example

21
Q

Which pattern allows us to recover previous states of an object so that it can be restored?

A

Memento
classic undo redo

21
Q

Which pattern decouples how we trasverse through objects of multiple collections while having types of collections?

A

Iterator

22
Q

Which pattern is used to modify the functionality of an object at runtime?

A

Decorator
interface Coffee
CoffeeLatteDecorator implements Coffee