Common design patterns in software engineering Flashcards

(26 cards)

1
Q

Define Singleton pattern.

A

A design pattern that restricts a class to a single instance.

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

True or false: The Observer pattern allows objects to notify others of state changes.

A

TRUE

Commonly used in event handling systems.

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

What is the purpose of the Factory pattern?

A

To create objects without specifying the exact class of object that will be created.

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

Fill in the blank: The Decorator pattern adds ______ to objects dynamically.

A

Responsibilities

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

Define Strategy pattern.

A

A design pattern that enables selecting an algorithm’s behavior at runtime.

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

What does the Facade pattern provide?

A

A simplified interface to a complex subsystem.

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

True or false: The Command pattern encapsulates a request as an object.

A

TRUE

This allows for parameterization and queuing of requests.

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

Define Adapter pattern.

A

A design pattern that allows incompatible interfaces to work together.

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

What is the Builder pattern used for?

A

To construct complex objects step by step.

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

Fill in the blank: The Prototype pattern creates new objects by ______.

A

Copying existing ones

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

Define Composite pattern.

A

A design pattern that allows treating individual objects and compositions uniformly.

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

What does the Chain of Responsibility pattern do?

A

It passes a request along a chain of handlers.

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

True or false: The State pattern allows an object to alter its behavior when its state changes.

A

TRUE

This pattern is useful for implementing state machines.

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

Define Mediator pattern.

A

A design pattern that facilitates communication between objects without them referring to each other.

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

What is the Template Method pattern?

A

A design pattern that defines the skeleton of an algorithm in a method.

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

Fill in the blank: The Visitor pattern lets you add new operations without changing ______.

A

The classes of the elements

17
Q

Define Memento pattern.

A

A design pattern that captures and externalizes an object’s internal state.

18
Q

What does the Interpreter pattern do?

A

It defines a representation for a language’s grammar and provides an interpreter.

19
Q

True or false: The Bridge pattern separates an abstraction from its implementation.

A

TRUE

This allows both to evolve independently.

20
Q

Define Proxy pattern.

A

A design pattern that provides a surrogate or placeholder for another object.

21
Q

What is the Flyweight pattern used for?

A

To minimize memory usage by sharing common parts of state among multiple objects.

22
Q

Fill in the blank: The Iterator pattern provides a way to access elements of a collection ______.

23
Q

Define Observer pattern.

A

A design pattern where an object (subject) maintains a list of dependents (observers) that are notified of state changes.

24
Q

What does the Null Object pattern do?

A

It uses a special object that represents ‘no action’ instead of null references.

25
True or false: The **Data Access Object pattern** abstracts data access logic.
TRUE ## Footnote This pattern separates the data persistence layer from the business logic.
26
Define **Service Locator pattern**.
A design pattern that provides a central point to access services.