Pattern Flashcards

1
Q

What is a design pattern in programming?

A

A design pattern is a general repeatable solution to a commonly occurring problem in software design.

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

True or False: Design patterns are specific implementations of code.

A

False

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

What are the three main categories of design patterns?

A

Creational, Structural, and Behavioral patterns.

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

Fill in the blank: The _____ pattern is used to create objects without specifying the exact class of object that will be created.

A

Factory

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

Which design pattern ensures a class has only one instance?

A

Singleton pattern.

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

What does the Adapter pattern do?

A

It allows incompatible interfaces to work together by converting the interface of a class into another interface that a client expects.

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

True or False: The Observer pattern defines a one-to-many dependency between objects.

A

True

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

What is the purpose of the Strategy pattern?

A

To define a family of algorithms, encapsulate each one, and make them interchangeable.

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

Which pattern is used to compose objects into tree structures to represent part-whole hierarchies?

A

Composite pattern.

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

Multiple Choice: Which of the following is a Creational pattern? A) Observer B) Factory C) Composite

A

B) Factory

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

What does the Decorator pattern allow you to do?

A

It allows behavior to be added to individual objects, either statically or dynamically, without affecting the behavior of other objects from the same class.

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

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

A

True

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

Fill in the blank: The _____ pattern provides a way to define a set of values, and allows you to create an object that can be used to represent one of those values.

A

Enum

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

What is the role of the Mediator pattern?

A

To define an object that encapsulates how a set of objects interact, promoting loose coupling.

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

Which design pattern is focused on simplifying complex structures into a more manageable form?

A

Facade pattern.

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

What is a key benefit of using design patterns?

A

They provide tested, proven development paradigms, which can speed up the development process.

17
Q

Multiple Choice: Which pattern is best for handling object creation in a way that allows for flexibility? A) Singleton B) Builder C) Observer

A

B) Builder

18
Q

True or False: The Prototype pattern creates new objects by copying an existing object.

19
Q

What is the main advantage of using the Bridge pattern?

A

It decouples an abstraction from its implementation, allowing both to vary independently.

20
Q

Fill in the blank: The _____ pattern is used to provide a unified interface to a set of interfaces in a subsystem.

21
Q

What is the purpose of the Chain of Responsibility pattern?

A

To pass a request along a chain of handlers, allowing multiple objects to handle the request.

22
Q

What is the main characteristic of the State pattern?

A

It allows an object to alter its behavior when its internal state changes.

23
Q

Which design pattern allows for the separation of concerns by defining a way to manage access to an object?

A

Proxy pattern.

24
Q

Multiple Choice: Which of the following patterns is classified as a Behavioral pattern? A) Builder B) Observer C) Singleton

A

B) Observer

25
Q

True or False: The Visitor pattern allows you to add new operations to existing object structures without modifying them.

26
Q

What does the Template Method pattern do?

A

It defines the skeleton of an algorithm in a method, deferring some steps to subclasses.