Question

OOD Question 2: Be able to explain and/or give an appropriate use of each of the...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

  • AbstractFactory : Declares an interface for operations that create abstract product objects.
  • ConcreteFactory : Implements the operations declared in the AbstractFactory to create concrete product objects.
  • Product : Defines a product object to be created by the corresponding concrete factory and implements the AbstractProduct interface.
  • Client : Uses only interfaces declared by AbstractFactory and AbstractProduct classes.

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 :

  • When you want to decouple a request’s sender and receiver
  • Multiple objects, determined at runtime, are candidates to handle a request
  • When you don’t want to specify handlers explicitly in your code
  • When you want to issue a request to one of several objects without specifying the receiver explicitly.

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.

  • Handler : This can be an interface which will primarily recieve the request and dispatches the request to chain of handlers. It has reference of only first handler in the chain and does not know anything about rest of the handlers.
  • Concrete handlers : These are actual handlers of the request chained in some sequential order.
  • Client : Originator of request and this will access the handler to handle it.

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.

Add a comment
Know the answer?
Add Answer to:
OOD Question 2: Be able to explain and/or give an appropriate use of each of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT