Sadp Unit 3 Modified
Sadp Unit 3 Modified
Patterns: Pattem Description, Organizing catalogs, role in solving design problems, Selection
and usage. Creational Patterns: Abstract factory. Builder, Factory method, Prololype. Singleton
Model -the lowest level of the pattern which is responsible for maintaining dala
View-this IS responsible tor displaying all or a portion ot the data to the user
Controller- Soflware Code that controls the interactions between the Model and View
MVC as it the
is popular isolates the application logic
concems. Here the Controller receives all
from user
interface layer and and
supports
separation of requests for the application then
works with the Model to prepare any data needed by the View. The View then uses the data
prepared by the Controller to generate a final presentable response. The MVC abstraction can be
graphically represented as follows.
Model
tate query State change
Encapsulates application state
-Responds tostate queries
nange
-
Exposes application functionality
otthcation
Nounes
views of changes
View Controller
Renders the models
Requestsupdates from models
View selection Definesapplication behavior
Maps user actions to model updates
Sends user gestures to controller Selects view for response
Allows controller to select view User gestures One for each functionality
******* ***
= Method Invocations
=Events
Organizing catalogs
Purpose
Creational Structural Behavioral
Scope Class Factory Method Adapter (class) Interpreter
Template Method
Object Abstract Factory Adapter (object) Chain of Responsibility
Builder Bridge Command
Prototype Composite lterator
Singleton Decorator Mediator
Fecade Memento
lyweight Obeerver
Proxy State
Strategy
Visitor
2ABSTRACT EACTORYE Provides an interface to create a family of related objects, without
explicitly specifying their concrete class.
Pattern name and classification
Intent: Provide an interface for creating families of related or dependent objects without
specifying their concrete classes.
Also known as: Kit
Motivation: Creating interface components for different look and feels.
whdgeiFectory CHent
CreateSerollBant) Window
CreateWindow)
PMWindow MotirWindow
MotirWidgetFectory PMWIdoetFectory - - -
CreateScrolBar() CreateScrollBar)
CreateWindow) CreateWindow() ScroBar -
PMScrollBer MotirscrollBar-
Applicability
We should use Abstract Factory design pattern when:
T h e system needs to be independent of the products it works with are created.
The system should be configured to work with multiple families of products.
A family of products is designed to be used together and this constraint is needed to be
enforced.
A library of products is to be provided and only their interfaces are to be revealed but not
their implementations.
Structure
Clet
AbatractFectory
CreateProductAO AbstrectProductA
CreateProdtctB0
ProductA2 ProductA
concretFectory Concretefectorya
CresteProductAO CreateProducA)
CroateProductB0 CreateProduciBK) ADetractProducte
Product81
Product82
Participants: The classes that participate in the Abstract Factory are: AbstractFactory.
ConcreteFactory, AbstractProduct, Product, Client
Collaborations
The ConcreteFactory class creates products objects having a particular implementation.
To create different product, the client should use a different concrete factory.
AbstractFactory defers creation of product objects to its ConcreteFactory subclass.
Consequences
It isolates concrete classes.
t makes exchanging product families easy.
It creates consistency among products.
Implementation
abstract class AbstractProductA
Sample code
public interface Window
Known uses
ET++ [WGM88] uses the Abstract Factory pattern to achieve portability across different window
systems (X Windows and SunView, for example).
Related patterns
AbstractFactory classes are often implemented with factory methods but they can also be
implemented using Prototype.
A concrete factory is often a Singleton.
4.FACTORYMETHOD
Pattern name and classification: Factory method and Creational
Intent: Define an interface for creating an object, but let subelasses decide which
Also known as: Virtual Constructor
Motivation: Frameworks use abstract classes to define and maintain relationships between
objects. A framework is often responsible for creating these objects as well.
Document CoAppcetion
Opend CreatoDocument)
Close0 NewDocumend) o Document doc CreateDocumenQ:
docs.Add(doc):
Seve) OpenDocument0 doc->Opon();
Revert)
MyDocument MyApplicato
ConerelePoduct ConereteCreator
catch(CloneNotSupportedException e)
return null;
Sample code
class MazeGame ( public:
Maze* CreateMaze():
I factory methods:
virtual Maze* MakeMaze() const
return new Maze: }
virtual Room* MakeRoom(int n) const
{return new Room(n); }
virtual Wall* Make Wall) const
return n ew Wall; }
virtual Door* MakeDoor(Room* rl, Room* r2) const
( return new Door(rl, 12);} }:
Known uses
Factory methods pervade toolkits and framework s.The preceding document example is a typical
use in MacApp and ET++. The manipulator example is from Unidraw.
Related patterns
Abstract Factory is often implemented with factory methods. as well.
.Factory methods are usually called within Template Methods
Prototypes don't require subclassing Creator.