Design Pattern Concretely Flashcards

1
Q

What is a design pattern?

A

A design pattern is a general reusable solution to a commonly occurring problem within a given context 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 to a programming language.

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 is used to ensure that 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 is a behavioral pattern.

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

In PHP 8, what feature enhances type safety in design patterns?

A

Union types and mixed types.

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

What is the main benefit of using design patterns?

A

They provide proven solutions to common problems, improving code maintainability and readability.

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

Multiple Choice: Which of the following is not a creational pattern? A) Builder B) Singleton C) Composite

A

C) Composite

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

What is the purpose of the Decorator pattern?

A

To add new functionality to an existing object without altering its structure.

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

True or False: The Command pattern is a structural pattern.

A

False

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

Fill in the blank: The _______ pattern allows an object to alter its behavior when its internal state changes.

A

State

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

What is the main advantage of using the Builder pattern?

A

It allows for the step-by-step construction of complex objects.

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

What does the Proxy pattern do?

A

It provides a surrogate or placeholder for another object to control access to it.

17
Q

Multiple Choice: Which pattern is used for lazy initialization? A) Singleton B) Builder C) Proxy

18
Q

What is the purpose of the Template Method pattern?

A

To define the skeleton of an algorithm in a method, deferring some steps to subclasses.

19
Q

True or False: The Mediator pattern promotes loose coupling by keeping objects from referring to each other explicitly.

20
Q

Fill in the blank: The _______ pattern is used to compose objects into tree structures to represent part-whole hierarchies.

21
Q

What is the main characteristic of the Visitor pattern?

A

It lets you separate algorithms from the objects on which they operate.

22
Q

Multiple Choice: Which design pattern is best suited for implementing a logging mechanism? A) Observer B) Strategy C) Decorator

A

C) Decorator

23
Q

What does the Chain of Responsibility pattern allow?

A

It allows multiple objects to handle a request without the sender needing to know which object will handle it.

24
Q

True or False: The Bridge pattern is a structural pattern that separates an abstraction from its implementation.

25
Q

What is the benefit of using interfaces in design patterns?

A

They promote loose coupling and allow for easier testing and maintenance.