Design Patterns Flashcards
Which pattern is used for 1 to many relationships between objects?
Observer Pattern
What are the actors used in observer patterns?
- Subject
- Object
- Client
What is a subject(Observable) actor in the Observer pattern?
It holds methods to attach and detach the observers to the client. it is a concrete class that extends the observer class
What is an Observer?
The observer is an abstract class with all the methods
What are design patterns?
Capture the best practice of experienced object-oriented s/w developers
What are the essential elements of patterns?
- Name
- Problem and its context
- Solution with an abstract description
- Consequences
Types of design patterns?
Creational Patterns
Structural Patterns
State Patterns
Command patterns
What are creational Patterns?
Create an object for you rather than having you to instantiate an object
What are Structural Patterns?
how to group. and organize classes
What are state patterns?
Class behavior changes on the basis of State
What are the elements of the state pattern?
- Context
- State
- ConcreteState
What is Context in state pattern?
The object whose behavior needs to be state-specific
It will have reference to a concrete state, which defines the current state of the context object. The state is proportional to Context.
What is State class in State Pattern?
It is implemented as an abstract class/Interface
What is a Concrete State in State Pattern?
The class that implements state-specific behavior, have the implementation of setState()
What is a Command Pattern?
It is a data-driven design pattern and falls under the behavior pattern category
What are the elements of Command Pattern?
- Interface acts as a command
- Class that acts as a request.
- Concrete command classes implementing the interface
- Class which act as an invoker object.
What are Strategy Patterns?
They are used when behavior changes are needed dynamically during runtime
What is the intent of Strategy Patterns?
- Define a group of algorithms that applies to a family of classes
- Encapsulate each algorithm separately
- Make the algorithms interchangeable within that family
What is the consequence of Strategy Patterns?
The Strategy Pattern lets the specific algorithm implemented by a method vary without affecting the clients that use it.
What are the elements of Strategy Patterns?
- Context
- Strategy Interface
- Concrete Strategy classes that implement Strategy Interface
What are Adapter Patterns?
It allows the classes to work together with incompatible types
What is the intent of Adapter Patterns?
- Convert the interface of a class into another interface that clients expect.
- The adapter lets classes work together, which could not otherwise because of incompatible interfaces.
What are the elements of the Adapter Pattern?
Target - defines the domain-specific interface that the Client uses.
Adapter - adapts the interface Adaptee to the Target interface.
Adaptee - defines an existing interface that needs adapting.
Client - collaborates with objects conforming to the Target interface.