Pattern Flashcards
What is a design pattern in programming?
A design pattern is a general repeatable solution to a commonly occurring problem in software design.
True or False: Design patterns are specific implementations of code.
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 ensures 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 defines a one-to-many dependency between objects.
True
What is the purpose of the Strategy pattern?
To define a family of algorithms, encapsulate each one, and make them interchangeable.
Which pattern is used to compose objects into tree structures to represent part-whole hierarchies?
Composite pattern.
Multiple Choice: Which of the following is a Creational pattern? A) Observer B) Factory C) Composite
B) Factory
What does the Decorator pattern allow you to do?
It allows behavior to be added to individual objects, either statically or dynamically, without affecting the behavior of other objects from the same class.
True or False: The Command pattern encapsulates a request as an object.
True
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.
Enum
What is the role of the Mediator pattern?
To define an object that encapsulates how a set of objects interact, promoting loose coupling.
Which design pattern is focused on simplifying complex structures into a more manageable form?
Facade pattern.
What is a key benefit of using design patterns?
They provide tested, proven development paradigms, which can speed up the development process.
Multiple Choice: Which pattern is best for handling object creation in a way that allows for flexibility? A) Singleton B) Builder C) Observer
B) Builder
True or False: The Prototype pattern creates new objects by copying an existing object.
True
What is the main advantage of using the Bridge pattern?
It decouples an abstraction from its implementation, allowing both to vary independently.
Fill in the blank: The _____ pattern is used to provide a unified interface to a set of interfaces in a subsystem.
Facade
What is the purpose of the Chain of Responsibility pattern?
To pass a request along a chain of handlers, allowing multiple objects to handle the request.
What is the main characteristic of the State pattern?
It allows an object to alter its behavior when its internal state changes.
Which design pattern allows for the separation of concerns by defining a way to manage access to an object?
Proxy pattern.
Multiple Choice: Which of the following patterns is classified as a Behavioral pattern? A) Builder B) Observer C) Singleton
B) Observer
True or False: The Visitor pattern allows you to add new operations to existing object structures without modifying them.
True
What does the Template Method pattern do?
It defines the skeleton of an algorithm in a method, deferring some steps to subclasses.