Design Pattern Concretely Flashcards
What is a design pattern?
A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
True or False: Design patterns are specific to a programming language.
False
What are the three main categories of design patterns?
Creational, Structural, and Behavioral patterns.
Fill in the blank: The _______ pattern is used to create objects without specifying the exact class of object that will be created.
Factory
Which design pattern is used to ensure that a class has only one instance?
Singleton pattern
What does the Adapter pattern do?
It allows incompatible interfaces to work together by converting the interface of a class into another interface that a client expects.
True or False: The Observer pattern is a behavioral pattern.
True
What is the purpose of the Strategy pattern?
To define a family of algorithms, encapsulate each one, and make them interchangeable.
In PHP 8, what feature enhances type safety in design patterns?
Union types and mixed types.
What is the main benefit of using design patterns?
They provide proven solutions to common problems, improving code maintainability and readability.
Multiple Choice: Which of the following is not a creational pattern? A) Builder B) Singleton C) Composite
C) Composite
What is the purpose of the Decorator pattern?
To add new functionality to an existing object without altering its structure.
True or False: The Command pattern is a structural pattern.
False
Fill in the blank: The _______ pattern allows an object to alter its behavior when its internal state changes.
State
What is the main advantage of using the Builder pattern?
It allows for the step-by-step construction of complex objects.
What does the Proxy pattern do?
It provides a surrogate or placeholder for another object to control access to it.
Multiple Choice: Which pattern is used for lazy initialization? A) Singleton B) Builder C) Proxy
C) Proxy
What is the purpose of the Template Method pattern?
To define the skeleton of an algorithm in a method, deferring some steps to subclasses.
True or False: The Mediator pattern promotes loose coupling by keeping objects from referring to each other explicitly.
True
Fill in the blank: The _______ pattern is used to compose objects into tree structures to represent part-whole hierarchies.
Composite
What is the main characteristic of the Visitor pattern?
It lets you separate algorithms from the objects on which they operate.
Multiple Choice: Which design pattern is best suited for implementing a logging mechanism? A) Observer B) Strategy C) Decorator
C) Decorator
What does the Chain of Responsibility pattern allow?
It allows multiple objects to handle a request without the sender needing to know which object will handle it.
True or False: The Bridge pattern is a structural pattern that separates an abstraction from its implementation.
True
What is the benefit of using interfaces in design patterns?
They promote loose coupling and allow for easier testing and maintenance.