OOP Design Patterns Flashcards

1
Q

What are Design Patterns in OOP?

A

Design patterns are reusable solutions to common software design problems. They provide proven approaches to structure code and improve maintainability, flexibility, and reusability.

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

What are the different categories of Design Patterns?

A

Design patterns are typically categorized as Creational, Structural, and Behavioral. Creational patterns focus on object creation, Structural patterns on object composition, and Behavioral patterns on communication between objects.

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

What is the Singleton Pattern?

A

Ensures a class has only one instance and provides a global access point to it.

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

What is the Factory Method Pattern?

A

Creates objects without specifying the exact class to be instantiated.

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

What is the Abstract Factory Pattern?

A

Provides an interface for creating families of related objects.

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

What is the Builder Pattern?

A

Separates object construction from its representation, allowing step-by-step object creation.

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

What is the Prototype Pattern?

A

Creates new objects by cloning an existing object.

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

What is the Adapter Pattern?

A

Allows incompatible interfaces to work together by wrapping an object with an adapter interface.

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

What is the Proxy Pattern?

A

Provides a surrogate or placeholder for another object to control access or add additional functionality.

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

What is the Decorator Pattern?

A

Adds new functionality to an object dynamically without altering its structure.

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

What is the Facade Pattern?

A

Provides a simplified interface to a complex system or a set of classes.

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

What is the Composite Pattern?

A

Treats a group of objects as a single object, allowing for composing parts into a tree structure.

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

What is the Strategy Pattern?

A

Defines a family of algorithms, encapsulates each one, and makes them interchangeable.

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

What is the Observer Pattern?

A

Defines a one-to-many dependency between objects when one object changes state, all its dependents are notified.

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

What is the Command Pattern?

A

Encapsulates a request as an object, allowing for parameterizing clients with different requests, queuing or logging requests, and undo/redo functionality.

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

What is the Template Method Pattern?

A

Defines the skeleton of an algorithm in an operation, deferring some steps to subclasses.

17
Q

What is the Iterator Pattern?

A

Provides a way to access the elements of an object collection sequentially without exposing its underlying representation.

18
Q

What is the State Pattern?

A

Allows an object to alter its behavior when its internal state changes.

19
Q

What is the Memento Pattern?

A

Without violating encapsulation, captures and externalizes an object’s internal state so it can be restored later.

20
Q

When to Use Design Patterns?

A

Use design patterns when you encounter recurring problems and need a proven, flexible solution. They are not a silver bullet and should be applied thoughtfully to avoid over-engineering.

21
Q

Situation: Only one “Settings” object needed in your app for global access.

A

Singleton Pattern - Ensures a single “Settings” instance exists for app-wide configuration access.

22
Q

Situation: Deciding between creating a “Button” or a “Dropdown” based on user input.

A

Factory Method Pattern - Hides button/dropdown creation logic, allowing for flexible UI element generation based on user choice.

23
Q

Situation: Integrating an old “Music Player” library with a new system that uses different controls.

A

Adapter Pattern - Acts as a bridge, allowing the new system to work with the old “Music Player” library despite incompatible interfaces.

24
Q

Situation: Adding new functionalities (like encryption) to an existing “Email” object without modifying its core functionality.

A

Decorator Pattern - Lets you dynamically add encryption functionality to the “Email” object without changing its core logic.

25
Q

Situation: Simplifying user interaction with a complex e-commerce “Shopping Cart” system.

A

Facade Pattern - Creates a simplified “Cart” interface that hides the complexities of managing items, discounts, and checkout within the shopping cart system