Class 26 - DP - Oct 26 Slot 2

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 20

AMRITA VISHWA VIDYAPEETHAM

AMRITA SCHOOL OF ENGINEERING


DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

15CSE343 DESIGN PATTERNS 3-0-0-3


COURSE INSTRUCTOR : Dr N LALITHAMANI

B. Tech . / Semester 7 ( ODD ) – Elective IV - July 2021 – Nov 2021

Total number of students : 136

Total no of hours: 42
Total no of Discussion hours : 16

CLASS SESSION SCHEDULE


MONDAY(SLOT 1): 8:50 AM TO 9:40 AM
TUESDAY(SLOT 2) : 9:50 AM TO 10:40 AM
THURSDAY(SLOT 1) : 8:50 AM TO 9:40 AM
DISCUSSION HOUR :
Apr 4, 2024 SATURDAY ( SLOT 3 ): 11:00 AM TO 11:50 AM 1
Design Pattern Space
• Creational – When & how objects are
instantiated
• Structural – how objects are composed to
form larger groups
• Behavioral – how responsibilities are
distributed
Describing Design Patterns
• Pattern Name and Classification
• Intent
• Also known As
• Motivation
• Applicability
• Structure
• Participants
• Collaborations
• Consequences
• Known uses
• Related Patterns
Behavioral Patterns
• Chain of Responsibility [COR]
• Command
• Interpreter
• Iterator
• Mediator
• Memento
• Observer
• State
• Strategy
• Template
• Visitor
Mediator-
Object Behavioral
Intent
• Promotes loose coupling by keeping objects
from referring to each other explicitly
Applicability
• Recurring
• Set of objects communicate
Participants
• Mediator
 Defines an Interface for communicating with colleague
objects
• Concrete mediator
 Implements cooperative behavior by coordinating colleague
objects
 Knows and maintains its colleagues
• Colleague Classes
 Each of this known its Mediator object
 Each colleague communicates with its Mediator whenever it
would have communicated with another colleague
Collaborations
• Colleagues send and receive requests from a
Mediator object.
• Mediator implements the behavior by routing
requests between appropriate colleagues
Consequences

• Limits subclassing
• Decouples colleagues
• Simplifies object protocols
• Centralizes control
• Abstracts how objects cooperate
Implementation
• Omitting abstract mediator class
• Colleague-Mediator communication
Related Patterns
• Façade
• Mediator
MEMENTO
INTENT

• Without violating encapsulation captise and externalize

object’s internal state so that object can be restored.


APPLICABILITY

• Snapshot of object’s static must be saved so that it can be


restored to that static later.
• Direct interface to get the static would expose implementation
details and break the objects encapsulation.
PARTICIPANTS
• Memento
– stores internal state of originator.
• Originator
– creates a snapshot of current internal state
• Caretaker
– safe keeping
COLLABORATION

• Caretaker requests memento from originator holds it for a time


and passes back to originator.
• Mementos are passive. Only originator that created a memento
will assign or retrieve its state.
CONSEQUENCES

• Preserving encapsulation boundaries.


• Simplifies originator.
• Defines narrow and wide interfaces.
• Hidden costs
IMPLEMENTATION

• Large support
• Storing incremental changes
RELATED PATTERNS

• Commands
– use mementos to maintain state for undoable operations.

• Iterator
– mementos to iterate.

You might also like