0% found this document useful (0 votes)
34 views19 pages

Unit-04-Design Patterns For Lab

The document discusses design patterns, which are best practices for solving common problems in object-oriented software development. It categorizes design patterns into three types: Creational, Structural, and Behavioral, and explains their elements, applicability, and implementation. Additionally, it highlights the Model/View/Controller (MVC) pattern used in Smalltalk for building user interfaces, emphasizing the decoupling of models and views for increased flexibility and reuse.

Uploaded by

srijagedela57
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views19 pages

Unit-04-Design Patterns For Lab

The document discusses design patterns, which are best practices for solving common problems in object-oriented software development. It categorizes design patterns into three types: Creational, Structural, and Behavioral, and explains their elements, applicability, and implementation. Additionally, it highlights the Model/View/Controller (MVC) pattern used in Smalltalk for building user interfaces, emphasizing the decoupling of models and views for increased flexibility and reuse.

Uploaded by

srijagedela57
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Unit -04

Design patterns
What is a design pattern?
Design patterns in Smalltalk MVC
Describing design patterns
How to select a design pattern?
How to use a design pattern.?
What is a Design Pattern?
Design patterns represent the best practices
used by experienced object-oriented software
developers. Design patterns are solutions to
general problems that software developers
faced during software development. These
solutions were obtained by trial and error by
numerous software developers over quite a
substantial period of time.
Types of Design Patterns
As per the design pattern reference book ”Design
Patterns - Elements of Reusable Object-Oriented
Software” , there are 23 design patterns which can
be classified in three categories:
Creational
 Structural
 Behavioral patterns.
Creational Design patterns

These design patterns specifies object


creation mechanisms, hiding the creation
logic, rather than instantiating objects
directly using new operator. Trying to
create in a manner suitable to the
situation.The basic form of object creation
may result in design problems.
Example:Abstract factory,singleton
Structural patterns
These Patterns ease the design by identifying a
simple way to realize relationships(Class and object
composition) between entities. This pattern focuses
on decoupling interface and implementation of
classes and its objects.
Adapter, bridge and composite
Behavioral Patterns
Identify common communication patterns between objects
and realize these patterns
These patterns increase flexibility in carrying out this
communication. Examples: chain of responsibilty,
command, interpreter etc;
Design Pattern Elements
1. Pattern Name
Handle used to describe the design problem
Increases vocabulary
Eases design discussions
Evaluation without implementation details
2. Problem
Describes when to apply a pattern
May include conditions for the pattern to be applicable
Symptoms of an inflexible design or limitation
3. Solution
Describes elements for the design
Includes relationships, responsibilities, and collaborations
Does not describe concrete designs or implementations
A pattern is more of a template
4. Consequences
Results and Trade Offs
Critical for design pattern evaluation
Often space and time trade offs
Language strengths and limitations
)
Design patterns in Smalltalk MVC
 The Model/View/Controller pattern is used to build user interfaces in
Smalltalk-80

 MVC consists of three kinds of objects.


 M-MODEL is the Application object.
 V-View is the screen presentation.
 C-Controller is the way the user interface reacts to user input.

 MVC decouples to increase flexibility and reuse.


• MVC decouples views and models by establishing a subscribe/notify
protocol between them.
• A view must ensure that its appearance must reflects the state of the
model.
• Whenever the model’s data changes, the model notifies views that
depends on it.
• You can also create new views for a model without Rewriting it.
Design Patterns in Smalltalk MVC
 The below diagram shows a model and three
views.
 The model contains some data values, and
the views defining a spreadsheet, histogram,
and pie chart display these data in various
ways.
 The model communicates when it’s values
change, and the views communicate with the
model to access these values.
 It reflects a design that decouples views from
models.
 The controller contains response mechanism.
Design Patterns in Smalltalk MVC

Relative Percentages
A B C D
A
X 15 35 35 15 D
Y 10 40 30 20 B
C
Z 10 40 30 20
A B C D

A=10%
B=40%
C=30% Application data
Change notification
D=20%
Requests, modifications
Describing Design Patterns
Pattern Name and Classification:
 it conveys the essence of the pattern , good name
is vital, because it will become part of design
vocabulary.
Intent: What does the design pattern do?
 What is it’s rational and intend?
 What particular design issue or problem does it
address?

Motivation:
 A scenario that illustrates a design problem and
how the class and object structures in the pattern
solve the problem.
 The scenario will help understand the more abstract
description of the pattern that follows.
Applicability:
• Applicability: What are the situations in which the
design patterns can be applied?
• What are example of the poor designs that the
pattern can address?
• How can recognize situations? .
Structure: Graphical representation of the classes in the
pattern using a notation based on the object
Modeling Technique(OMT).
Participants: The classes and/or objects participating in
the design pattern and their responsibilities.
Collaborations: How the participants collaborate to
carry out their responsibilities.
Consequences:
 How does the pattern support its objectives?
 What are the trade-offs and result of using the
pattern ?What aspect of the system structure does it
let vary independently?
Implementation:
What pitfalls, hints, or techniques should be
aware of when implementing the pattern ?
Are there language-specific issues?

Sample Code: Code fragments that illustrate


how might implement the pattern in c++ or
Smalltalk.
Known Uses: Examples of the pattern found in
real systems.
Related Patterns: What design patterns are
closely related to this one? What are the imp
differences? With Which other patterns should
this one be used?
L7

How To Select a Design Pattern


Consider how design patterns solve design
problems – it guides your search for the
right pattern.
Scan Intent sections – to check the
relevance of a design pattern to your
problem.
Study how patterns interrelate-it directs you
to the right pattern or group of patterns .

UNIT-I 13
Study patterns of like purpose-know the
similarities and differences between patterns
of like purpose.

Examine a cause of redesign

Consider what should be variable in your


design-consider what you can change
without redisign.
How To Use a Design Pattern
 Read the pattern once through for an overview-see
that the pattern is right for your problem.
 Go Back and study the Structure, Participants ,and
Collaborations sections.
 Look At the Sample Code section to see a concrete
Example of the pattern in code.
Choose names for pattern participants that are
meaningful in the application context.
Define the classes-declare their interfaces,establish
their inheritance relationships
UNIT-I
and define instance
15

variables
Define application specifics names for
operations in the pattern.

Implement the operations to carry out the


responsibilities and collaborations in the
pattern.
Purpose Design pattern Aspects that can
vary
creational 1. Abstract 1.Families of product
factory Objects
2. Builder 2.How a composite
object gets created
3. Factory method 3.Subclass of object
4. Prototype that is instantiated
5. singleton 4.Class of object that
is instantiated
5.The sole instance of
a class
Purpose Design pattern Aspects that can vary

Structural 1. Adaptor 1. Interface to an


2. Bridge object
2. Implementation of an
3. Composite object
4. Decorator 3. Structure and
5. Facade composition of an
object
6. Flyweight 4. Responsibilities of an
7. Proxy object without
subclassing
5. Interface to a
subsystem

6. Storage costs of
objects
Purpose Design pattern Aspects that can vary

Behavioral 1. Chain of 1) Object that can fulfill a


request
responsibility 2) When and how a
2. Command request is fulfilled
3. Interpreter 3) Grammar and
interpretation of a
4. Iterator language
5. State 4) How an aggregates
6. strategy elements are accessed
and traversed
7. Template method 5) State of an object
8. Mediator 6) An algorithm
9. Observer 7) Steps of an algorithm
10. Visitor
11. memento

You might also like