OOD Question 2:
Be able to explain and/or give an appropriate use of each of the following design patterns:
Abstract Factory Adapter Bridge
Builder Chain of Responsibility Command
Composite Decorator Facade
Factory Flyweight Iterator
Mediator Momento Null Object
Observer Prototype Singleton
State Strategy Template Method
Visitor
1.
Abstract Factory design pattern is one of the Creational pattern. Abstract Factory pattern is almost similar to Factory Pattern is considered as another layer of abstraction over factory pattern. Abstract Factory patterns work around a super-factory which creates other factories.
Abstract factory pattern implementation provides us a framework that allows us to create objects that follow a general pattern. So at runtime, abstract factory is coupled with any desired concrete factory which can create objects of desired type.
UML class diagram example for the Abstract Factory Design Pattern.
Abstract Factory provides interfaces for creating families of related or dependent objects without specifying their concrete classes.
Client software creates a concrete implementation of the
abstract factory and then uses the generic interfaces to create the
concrete objects that are part of the family of objects.
The client does not know or care which concrete objects it gets
from each of these concrete factories since it uses only the
generic interfaces of their products.
2.
Chain of responsibility pattern is used to achieve loose coupling in software design where a request from the client is passed to a chain of objects to process them. Later, the object in the chain will decide themselves who will be processing the request and whether the request is required to be sent to the next object in the chain or not.
Where and When Chain of Responsibility pattern is applicable :
This pattern is recommended when multiple objects can handle a request and the handler doesn’t have to be a specific object. Also, the handler is determined at runtime. Please note that a request not handled at all by any handler is a valid use case.
How to send a request in the application using the Chain of Responsibility
The Client in need of a request to be handled sends it to the
chain of handlers which are classes that extend the Handler
class.
Each of the handlers in the chain takes its turn at trying to
handle the request it receives from the client.
NOTE: As per Chegg policy, I am allowed to answer only 2 questions (including sub-parts) on a single post. Kindly post the remaining questions separately and I will try to answer them. Sorry for the inconvenience caused.
OOD Question 2: Be able to explain and/or give an appropriate use of each of the...