SlideShare a Scribd company logo
1 of 42
Design Patterns
By: Sari Meriem
1
UNIVERSITY of MOHAMED CHERIF MESAADIA
SOUK-AHRAS
Departement of Math & Computer Science
Presentation About:
Motivation
2Meriem Sari GL à Objet 2 2eme AM GL
 Designing object-oriented software is hard.
 Designing a reusable object-oriented software is even harder.
 Hard to find objects and collect them at the right granularity.
 Hard to define class interfaces and inheritance hierarchies.
 Hard to establish key relationships among classes.
 The design should be specific to one problem but general enough
to address future problems.
Motivation
3
 Expert designers reuse existing solutions to solve new problems.
 Recurring patterns of classes and communicating objects in many
object-oriented systems.
 Applying these patterns will make the software design flexible,
elegant, and ultimately reusable.
Meriem Sari GL à Objet 2 2eme AM GL
History
4
 In this presentation we will consider the patterns published in the
book: «Design Patterns - Elements of Reusable Object-Oriented
Software» by the GOF.
Meriem Sari GL à Objet 2 2eme AM GL
History
5
Erich Gamma Ralph Johnson John Vlissides Richard Helm
Meriem Sari GL à Objet 2 2eme AM GL
Outline
6Meriem Sari GL à Objet 2 2eme AM GL
 Definition.
 Classification.
 State Design Pattern.
 Strategy Design Pattern.
 Visitor Design Pattern.
Definition
7
 According to Christopher Alexander:
 A pattern describes a problem which occurs over and over.
 It describes the core of the solution to that problem.
 This solution can be used a million times over, without ever doing
it the same way twice.
Meriem Sari GL à Objet 2 2eme AM GL
Definition
8
 Each pattern has four basic elements:
 The pattern name: each pattern name describes the problem that this
pattern solves to ease the documentation and the communication
between designers and developers.
 The problem: describes when to apply this pattern.
 The solution: describes the general arrangement of elements (classes
and objects ) that solves problem.
 The consequences: describe the results of applying the pattern in
order to evaluate design alternatives and understanding the costs and
benefits of applying the pattern.
Meriem Sari GL à Objet 2 2eme AM GL
Classification
9
 Design patterns vary in their granularity and level of abstraction.
 They are classified by two criteria:
 By purpose i.e. what a pattern does.
 Creational patterns: concern the process of object creation.
 Structural patterns: deal with the composition of classes or objects.
 Behavioral patterns: characterize the ways in which classes or objects
interact .
 By scope i.e. whether the pattern applies primarily to classes or to
objects.
Meriem Sari GL à Objet 2 2eme AM GL
Classification
10Meriem Sari GL à Objet 2 2eme AM GL
Design Patterns
11
 In this presentation we’re gonna abord three behavioral patterns
which are:
 State design pattern.
 Strategy design pattern.
 Visitor design pattern.
Meriem Sari GL à Objet 2 2eme AM GL
State Pattern
12
 Definition.
 Purpose.
 Structure.
 Consequences.
 Example.
Meriem Sari GL à Objet 2 2eme AM GL
Definition
13
 Known as: Objects for States.
 An object's behavior depends on its state.
 Allows the object to alter its behavior when its internal state
changes.
 This change happens in run-time.
 Encapsulates varying behavior of the same object based on its
states.
 Creates objects for various states and a context object whose
behavior depends on those objects’ state change.
Meriem Sari GL à Objet 2 2eme AM GL
Purpose
14
 Minimizes the use of conditional statements that leads to
changing the state of an object.
 Puts each branch of the conditional statement in a separate class.
 It allows us to treat the object's state as an object in its own that
varies independently from other objects.
Meriem Sari GL à Objet 2 2eme AM GL
Structure (1)
15Meriem Sari GL à Objet 2 2eme AM GL
Structure (2)
16
 Context: defines the interface of interest to clients and maintain the
instance of a Concrete State subclass that defines the current state.
 State: defines an interface for encapsulating the behavior associated
with a particular state of the Context.
 Concrete State Subclass: each subclass implements a behavior
associated with a state of the Context.
Meriem Sari GL à Objet 2 2eme AM GL
Consequences
17
 The State pattern puts all behavior associated with a particular
state into one object.
 When an object defines its current state internally, its state
transitions have no explicit representation i.e. they only show up as
assignments to some variables.
 State objects can be shared between Contexts (Flyweight).
Meriem Sari GL à Objet 2 2eme AM GL
Example (1)
18Meriem Sari GL à Objet 2 2eme AM GL
Example (Implementation)
19Meriem Sari GL à Objet 2 2eme AM GL
Example (Implementation)
20Meriem Sari GL à Objet 2 2eme AM GL
Strategy Pattern
21Meriem Sari GL à Objet 2 2eme AM GL
 Definition.
 Purpose.
 Structure.
 Consequences.
 Example.
Definition
22Meriem Sari GL à Objet 2 2eme AM GL
 Known as: Policy pattern.
 Enables an algorithm's behavior to be selected at runtime.
 Changes the executing algorithm of the context object.
 Lets the algorithm vary independently from clients that use it.
 Defines a family of algorithms and encapsulates each one.
 Makes algorithms interchangeable between families.
Purpose
23Meriem Sari GL à Objet 2 2eme AM GL
Configure many related classes which differ only in their behavior.
 Very helpful in validation on in coming data based algorithms.
 Type of data.
 The source of the data.
 The user choice…
 Used by other objects in different areas of the system or even
different systems without duplicating the code.
Structure (1)
24Meriem Sari GL à Objet 2 2eme AM GL
Structure (2)
25Meriem Sari GL à Objet 2 2eme AM GL
 Context : maintains a reference to a Strategy object and configured
with a ConcreteStrategy object.
 Strategy: declares an interface common to all supported algorithms.
 ConcreteStrategy: implements the algorithm using the Strategy
interface.
Consequences
26Meriem Sari GL à Objet 2 2eme AM GL
 Encapsulating all the behaviors in one class makes it hard to avoid
conditional statements.
 Eliminates the use of conditional statements.
 Provides different implementations of the same behavior.
 Increases the number of objects in an application.
Example (1)
27Meriem Sari GL à Objet 2 2eme AM GL
Calculator
Example (Implementation)
28Meriem Sari GL à Objet 2 2eme AM GL
Example (Implementation)
29Meriem Sari GL à Objet 2 2eme AM GL
Visitor Pattern
30Meriem Sari GL à Objet 2 2eme AM GL
 Definition.
 Purpose.
 Structure.
 Consequences.
 Example.
Definition
31Meriem Sari GL à Objet 2 2eme AM GL
 Represents an operation to be performed on the elements of an
object structure.
 Allows the addition of new operations without changing the
structure of the object.
 Separates the algorithm from the object structure on which it
operates.
 Allows the addition of new virtual functions in a classes without
modifying it.
 It is one way to follow the open/closed principle.
Purpose
32Meriem Sari GL à Objet 2 2eme AM GL
 Consider a compiler that represents programs as abstract syntax
trees.
 We’ll need to perform operations on abstract syntax trees
(configure the nodes).
 Compiling + Configuring = a hard to understand system(complex).
 Visitor design pattern allows us to configure the abstract syntax
tree without polluting the source code of the original programe
which is the compiler.
Structure (1)
33Meriem Sari GL à Objet 2 2eme AM GL
Structure (2)
34Meriem Sari GL à Objet 2 2eme AM GL
 Visitor: declares a Visit operation for each class of ConcreteElement .
 The operation's name and signature identifies the class that sends the
Visit request to the visitor.
 ConcreteVisitor: implements each operation declared by Visitor.
 Element: defines an Accept operation that takes a visitor as an
argument.
 ConcreteElement: implements an Accept operation that takes a visitor
as an argument.
Structure (3)
35Meriem Sari GL à Objet 2 2eme AM GL
 Consider two objects: one is called the "element", the other is
called the "visitor".
 An element has an accept() method that can take the visitor as an
argument.
 The accept() method calls a visit() method of the visitor.
 The element passes itself as an argument to the visit() method.
Example (1)
36Meriem Sari GL à Objet 2 2eme AM GL
Example (Implementation)
37Meriem Sari GL à Objet 2 2eme AM GL
Example (Implementation)
38Meriem Sari GL à Objet 2 2eme AM GL
Example (Implementation)
39Meriem Sari GL à Objet 2 2eme AM GL
Example (Implementation)
40Meriem Sari GL à Objet 2 2eme AM GL
Conclusion
41
If we don't study design patterns in software, we won't be able to
improve them, and it'll be harder to come up with new ones.
Meriem Sari GL à Objet 2 2eme AM GL
Acknowledgment
42
Thank You For Paying Attention
Meriem Sari GL à Objet 2 2eme AM GL

More Related Content

Viewers also liked

Vbisigk
VbisigkVbisigk
Vbisigk
ISIG
 
Environnement de développement de bases de données
Environnement de développement de bases de donnéesEnvironnement de développement de bases de données
Environnement de développement de bases de données
ISIG
 
Developpement mobile vs open source
Developpement mobile vs open sourceDeveloppement mobile vs open source
Developpement mobile vs open source
Korteby Farouk
 

Viewers also liked (20)

Design patterns
Design patternsDesign patterns
Design patterns
 
Embedded OCL Integration and Debugging
Embedded OCL Integration and DebuggingEmbedded OCL Integration and Debugging
Embedded OCL Integration and Debugging
 
OCCIware
OCCIwareOCCIware
OCCIware
 
Model Transformation: A survey of the state of the art
Model Transformation: A survey of the state of the artModel Transformation: A survey of the state of the art
Model Transformation: A survey of the state of the art
 
Collaboration and Governance of Open Source Projects
Collaboration and Governance of Open Source ProjectsCollaboration and Governance of Open Source Projects
Collaboration and Governance of Open Source Projects
 
OCCIware Contribution to the EU consultation on Cloud Computing Research Inno...
OCCIware Contribution to the EU consultation on Cloud Computing Research Inno...OCCIware Contribution to the EU consultation on Cloud Computing Research Inno...
OCCIware Contribution to the EU consultation on Cloud Computing Research Inno...
 
UMLX and QVT and ATL
UMLX and QVT and ATLUMLX and QVT and ATL
UMLX and QVT and ATL
 
Vbisigk
VbisigkVbisigk
Vbisigk
 
Frame latency evaluation: when simulation and analysis alone are not enough
Frame latency evaluation: when simulation and analysis alone are not enoughFrame latency evaluation: when simulation and analysis alone are not enough
Frame latency evaluation: when simulation and analysis alone are not enough
 
Modeling the OCL Standard Library
Modeling the OCL Standard LibraryModeling the OCL Standard Library
Modeling the OCL Standard Library
 
Model Transformation A Personal Perspective
Model Transformation A Personal PerspectiveModel Transformation A Personal Perspective
Model Transformation A Personal Perspective
 
Environnement de développement de bases de données
Environnement de développement de bases de donnéesEnvironnement de développement de bases de données
Environnement de développement de bases de données
 
What fUML can bring to MBSE?
What fUML can bring to MBSE?What fUML can bring to MBSE?
What fUML can bring to MBSE?
 
OCCIware, an extensible, standard-based XaaS consumer platform to manage ever...
OCCIware, an extensible, standard-based XaaS consumer platform to manage ever...OCCIware, an extensible, standard-based XaaS consumer platform to manage ever...
OCCIware, an extensible, standard-based XaaS consumer platform to manage ever...
 
The Importance of Opposites
The Importance of OppositesThe Importance of Opposites
The Importance of Opposites
 
Fast, Faster and Super-Fast Queries
Fast, Faster and Super-Fast QueriesFast, Faster and Super-Fast Queries
Fast, Faster and Super-Fast Queries
 
Developpement mobile vs open source
Developpement mobile vs open sourceDeveloppement mobile vs open source
Developpement mobile vs open source
 
OCL Specification Status
OCL Specification StatusOCL Specification Status
OCL Specification Status
 
Aligning OCL and UML
Aligning OCL and UMLAligning OCL and UML
Aligning OCL and UML
 
Local Optimizations in Eclipse QVTc and QVTr using the Micro-Mapping Model of...
Local Optimizations in Eclipse QVTc and QVTr using the Micro-Mapping Model of...Local Optimizations in Eclipse QVTc and QVTr using the Micro-Mapping Model of...
Local Optimizations in Eclipse QVTc and QVTr using the Micro-Mapping Model of...
 

Similar to Design patterns english

Design Patterns
Design PatternsDesign Patterns
Design Patterns
soms_1
 
ArchitectureOfAOMsWICSA3
ArchitectureOfAOMsWICSA3ArchitectureOfAOMsWICSA3
ArchitectureOfAOMsWICSA3
Erdem Sahin
 
Object-oriented modeling and design.pdf
Object-oriented modeling and  design.pdfObject-oriented modeling and  design.pdf
Object-oriented modeling and design.pdf
SHIVAM691605
 
Introduction to Object orientation , Modeling as a Design Technique Modeling ...
Introduction to Object orientation , Modeling as a Design Technique Modeling ...Introduction to Object orientation , Modeling as a Design Technique Modeling ...
Introduction to Object orientation , Modeling as a Design Technique Modeling ...
DhwaniDesai21
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 

Similar to Design patterns english (20)

Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
ALMOsT.js: an Agile Model to Model and Model to Text Transformation Framework
ALMOsT.js: an Agile Model to Model and Model to Text Transformation FrameworkALMOsT.js: an Agile Model to Model and Model to Text Transformation Framework
ALMOsT.js: an Agile Model to Model and Model to Text Transformation Framework
 
TEST PPT
TEST PPTTEST PPT
TEST PPT
 
Object oriented analysis and design using uml classes and objects
Object oriented analysis and  design using uml  classes and objectsObject oriented analysis and  design using uml  classes and objects
Object oriented analysis and design using uml classes and objects
 
Object-Oriented Analysis and Design
Object-Oriented Analysis and DesignObject-Oriented Analysis and Design
Object-Oriented Analysis and Design
 
ArchitectureOfAOMsWICSA3
ArchitectureOfAOMsWICSA3ArchitectureOfAOMsWICSA3
ArchitectureOfAOMsWICSA3
 
Strategy and Template Pattern
Strategy and Template PatternStrategy and Template Pattern
Strategy and Template Pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
What is design pattern
What is design patternWhat is design pattern
What is design pattern
 
Collections for States
Collections for StatesCollections for States
Collections for States
 
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
 
Object oriented modeling and design
Object oriented modeling and designObject oriented modeling and design
Object oriented modeling and design
 
Oomd unit1
Oomd unit1Oomd unit1
Oomd unit1
 
Object oriented modeling and design
Object oriented modeling and designObject oriented modeling and design
Object oriented modeling and design
 
Object-oriented modeling and design.pdf
Object-oriented modeling and  design.pdfObject-oriented modeling and  design.pdf
Object-oriented modeling and design.pdf
 
Ch14
Ch14Ch14
Ch14
 
Introduction to Object orientation , Modeling as a Design Technique Modeling ...
Introduction to Object orientation , Modeling as a Design Technique Modeling ...Introduction to Object orientation , Modeling as a Design Technique Modeling ...
Introduction to Object orientation , Modeling as a Design Technique Modeling ...
 
lecture 3.ppt
lecture  3.pptlecture  3.ppt
lecture 3.ppt
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 

More from meriem sari (13)

Contraintes uml
Contraintes umlContraintes uml
Contraintes uml
 
Cvs
CvsCvs
Cvs
 
Ws asp.net
Ws asp.netWs asp.net
Ws asp.net
 
What is an aspect in aspect oriented requirements engineering
What is an aspect in aspect oriented requirements engineeringWhat is an aspect in aspect oriented requirements engineering
What is an aspect in aspect oriented requirements engineering
 
Structural features for face recognition
Structural features for face recognitionStructural features for face recognition
Structural features for face recognition
 
Rest ws
Rest wsRest ws
Rest ws
 
Qt user interface
Qt user interfaceQt user interface
Qt user interface
 
Programmation orienté aspect
Programmation orienté aspectProgrammation orienté aspect
Programmation orienté aspect
 
Meta-modelisation avec eclipse
Meta-modelisation avec eclipseMeta-modelisation avec eclipse
Meta-modelisation avec eclipse
 
Diagrammes de classes uml
Diagrammes de classes umlDiagrammes de classes uml
Diagrammes de classes uml
 
Design patterns french
Design patterns frenchDesign patterns french
Design patterns french
 
Cvl
CvlCvl
Cvl
 
A star
A starA star
A star
 

Recently uploaded

一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
pyhepag
 
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
Amil baba
 
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
dq9vz1isj
 
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
pyhepag
 
一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理
cyebo
 
edited gordis ebook sixth edition david d.pdf
edited gordis ebook sixth edition david d.pdfedited gordis ebook sixth edition david d.pdf
edited gordis ebook sixth edition david d.pdf
great91
 
Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...
Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...
Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...
Valters Lauzums
 
如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一
如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一
如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一
fztigerwe
 
一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理
pyhepag
 

Recently uploaded (20)

一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
 
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
 
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
1:1原版定制伦敦政治经济学院毕业证(LSE毕业证)成绩单学位证书留信学历认证
 
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
 
123.docx. .
123.docx.                                 .123.docx.                                 .
123.docx. .
 
一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理
 
The Significance of Transliteration Enhancing
The Significance of Transliteration EnhancingThe Significance of Transliteration Enhancing
The Significance of Transliteration Enhancing
 
Generative AI for Trailblazers_ Unlock the Future of AI.pdf
Generative AI for Trailblazers_ Unlock the Future of AI.pdfGenerative AI for Trailblazers_ Unlock the Future of AI.pdf
Generative AI for Trailblazers_ Unlock the Future of AI.pdf
 
社内勉強会資料  Mamba - A new era or ephemeral
社内勉強会資料   Mamba - A new era or ephemeral社内勉強会資料   Mamba - A new era or ephemeral
社内勉強会資料  Mamba - A new era or ephemeral
 
Easy and simple project file on mp online
Easy and simple project file on mp onlineEasy and simple project file on mp online
Easy and simple project file on mp online
 
Seven tools of quality control.slideshare
Seven tools of quality control.slideshareSeven tools of quality control.slideshare
Seven tools of quality control.slideshare
 
How to Transform Clinical Trial Management with Advanced Data Analytics
How to Transform Clinical Trial Management with Advanced Data AnalyticsHow to Transform Clinical Trial Management with Advanced Data Analytics
How to Transform Clinical Trial Management with Advanced Data Analytics
 
edited gordis ebook sixth edition david d.pdf
edited gordis ebook sixth edition david d.pdfedited gordis ebook sixth edition david d.pdf
edited gordis ebook sixth edition david d.pdf
 
Artificial_General_Intelligence__storm_gen_article.pdf
Artificial_General_Intelligence__storm_gen_article.pdfArtificial_General_Intelligence__storm_gen_article.pdf
Artificial_General_Intelligence__storm_gen_article.pdf
 
Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...
Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...
Data Analytics for Digital Marketing Lecture for Advanced Digital & Social Me...
 
如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一
如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一
如何办理哥伦比亚大学毕业证(Columbia毕业证)成绩单原版一比一
 
2024 Q1 Tableau User Group Leader Quarterly Call
2024 Q1 Tableau User Group Leader Quarterly Call2024 Q1 Tableau User Group Leader Quarterly Call
2024 Q1 Tableau User Group Leader Quarterly Call
 
Genuine love spell caster )! ,+27834335081) Ex lover back permanently in At...
Genuine love spell caster )! ,+27834335081)   Ex lover back permanently in At...Genuine love spell caster )! ,+27834335081)   Ex lover back permanently in At...
Genuine love spell caster )! ,+27834335081) Ex lover back permanently in At...
 
一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理
 
Statistics Informed Decisions Using Data 5th edition by Michael Sullivan solu...
Statistics Informed Decisions Using Data 5th edition by Michael Sullivan solu...Statistics Informed Decisions Using Data 5th edition by Michael Sullivan solu...
Statistics Informed Decisions Using Data 5th edition by Michael Sullivan solu...
 

Design patterns english

  • 1. Design Patterns By: Sari Meriem 1 UNIVERSITY of MOHAMED CHERIF MESAADIA SOUK-AHRAS Departement of Math & Computer Science Presentation About:
  • 2. Motivation 2Meriem Sari GL à Objet 2 2eme AM GL  Designing object-oriented software is hard.  Designing a reusable object-oriented software is even harder.  Hard to find objects and collect them at the right granularity.  Hard to define class interfaces and inheritance hierarchies.  Hard to establish key relationships among classes.  The design should be specific to one problem but general enough to address future problems.
  • 3. Motivation 3  Expert designers reuse existing solutions to solve new problems.  Recurring patterns of classes and communicating objects in many object-oriented systems.  Applying these patterns will make the software design flexible, elegant, and ultimately reusable. Meriem Sari GL à Objet 2 2eme AM GL
  • 4. History 4  In this presentation we will consider the patterns published in the book: «Design Patterns - Elements of Reusable Object-Oriented Software» by the GOF. Meriem Sari GL à Objet 2 2eme AM GL
  • 5. History 5 Erich Gamma Ralph Johnson John Vlissides Richard Helm Meriem Sari GL à Objet 2 2eme AM GL
  • 6. Outline 6Meriem Sari GL à Objet 2 2eme AM GL  Definition.  Classification.  State Design Pattern.  Strategy Design Pattern.  Visitor Design Pattern.
  • 7. Definition 7  According to Christopher Alexander:  A pattern describes a problem which occurs over and over.  It describes the core of the solution to that problem.  This solution can be used a million times over, without ever doing it the same way twice. Meriem Sari GL à Objet 2 2eme AM GL
  • 8. Definition 8  Each pattern has four basic elements:  The pattern name: each pattern name describes the problem that this pattern solves to ease the documentation and the communication between designers and developers.  The problem: describes when to apply this pattern.  The solution: describes the general arrangement of elements (classes and objects ) that solves problem.  The consequences: describe the results of applying the pattern in order to evaluate design alternatives and understanding the costs and benefits of applying the pattern. Meriem Sari GL à Objet 2 2eme AM GL
  • 9. Classification 9  Design patterns vary in their granularity and level of abstraction.  They are classified by two criteria:  By purpose i.e. what a pattern does.  Creational patterns: concern the process of object creation.  Structural patterns: deal with the composition of classes or objects.  Behavioral patterns: characterize the ways in which classes or objects interact .  By scope i.e. whether the pattern applies primarily to classes or to objects. Meriem Sari GL à Objet 2 2eme AM GL
  • 10. Classification 10Meriem Sari GL à Objet 2 2eme AM GL
  • 11. Design Patterns 11  In this presentation we’re gonna abord three behavioral patterns which are:  State design pattern.  Strategy design pattern.  Visitor design pattern. Meriem Sari GL à Objet 2 2eme AM GL
  • 12. State Pattern 12  Definition.  Purpose.  Structure.  Consequences.  Example. Meriem Sari GL à Objet 2 2eme AM GL
  • 13. Definition 13  Known as: Objects for States.  An object's behavior depends on its state.  Allows the object to alter its behavior when its internal state changes.  This change happens in run-time.  Encapsulates varying behavior of the same object based on its states.  Creates objects for various states and a context object whose behavior depends on those objects’ state change. Meriem Sari GL à Objet 2 2eme AM GL
  • 14. Purpose 14  Minimizes the use of conditional statements that leads to changing the state of an object.  Puts each branch of the conditional statement in a separate class.  It allows us to treat the object's state as an object in its own that varies independently from other objects. Meriem Sari GL à Objet 2 2eme AM GL
  • 15. Structure (1) 15Meriem Sari GL à Objet 2 2eme AM GL
  • 16. Structure (2) 16  Context: defines the interface of interest to clients and maintain the instance of a Concrete State subclass that defines the current state.  State: defines an interface for encapsulating the behavior associated with a particular state of the Context.  Concrete State Subclass: each subclass implements a behavior associated with a state of the Context. Meriem Sari GL à Objet 2 2eme AM GL
  • 17. Consequences 17  The State pattern puts all behavior associated with a particular state into one object.  When an object defines its current state internally, its state transitions have no explicit representation i.e. they only show up as assignments to some variables.  State objects can be shared between Contexts (Flyweight). Meriem Sari GL à Objet 2 2eme AM GL
  • 18. Example (1) 18Meriem Sari GL à Objet 2 2eme AM GL
  • 19. Example (Implementation) 19Meriem Sari GL à Objet 2 2eme AM GL
  • 20. Example (Implementation) 20Meriem Sari GL à Objet 2 2eme AM GL
  • 21. Strategy Pattern 21Meriem Sari GL à Objet 2 2eme AM GL  Definition.  Purpose.  Structure.  Consequences.  Example.
  • 22. Definition 22Meriem Sari GL à Objet 2 2eme AM GL  Known as: Policy pattern.  Enables an algorithm's behavior to be selected at runtime.  Changes the executing algorithm of the context object.  Lets the algorithm vary independently from clients that use it.  Defines a family of algorithms and encapsulates each one.  Makes algorithms interchangeable between families.
  • 23. Purpose 23Meriem Sari GL à Objet 2 2eme AM GL Configure many related classes which differ only in their behavior.  Very helpful in validation on in coming data based algorithms.  Type of data.  The source of the data.  The user choice…  Used by other objects in different areas of the system or even different systems without duplicating the code.
  • 24. Structure (1) 24Meriem Sari GL à Objet 2 2eme AM GL
  • 25. Structure (2) 25Meriem Sari GL à Objet 2 2eme AM GL  Context : maintains a reference to a Strategy object and configured with a ConcreteStrategy object.  Strategy: declares an interface common to all supported algorithms.  ConcreteStrategy: implements the algorithm using the Strategy interface.
  • 26. Consequences 26Meriem Sari GL à Objet 2 2eme AM GL  Encapsulating all the behaviors in one class makes it hard to avoid conditional statements.  Eliminates the use of conditional statements.  Provides different implementations of the same behavior.  Increases the number of objects in an application.
  • 27. Example (1) 27Meriem Sari GL à Objet 2 2eme AM GL Calculator
  • 28. Example (Implementation) 28Meriem Sari GL à Objet 2 2eme AM GL
  • 29. Example (Implementation) 29Meriem Sari GL à Objet 2 2eme AM GL
  • 30. Visitor Pattern 30Meriem Sari GL à Objet 2 2eme AM GL  Definition.  Purpose.  Structure.  Consequences.  Example.
  • 31. Definition 31Meriem Sari GL à Objet 2 2eme AM GL  Represents an operation to be performed on the elements of an object structure.  Allows the addition of new operations without changing the structure of the object.  Separates the algorithm from the object structure on which it operates.  Allows the addition of new virtual functions in a classes without modifying it.  It is one way to follow the open/closed principle.
  • 32. Purpose 32Meriem Sari GL à Objet 2 2eme AM GL  Consider a compiler that represents programs as abstract syntax trees.  We’ll need to perform operations on abstract syntax trees (configure the nodes).  Compiling + Configuring = a hard to understand system(complex).  Visitor design pattern allows us to configure the abstract syntax tree without polluting the source code of the original programe which is the compiler.
  • 33. Structure (1) 33Meriem Sari GL à Objet 2 2eme AM GL
  • 34. Structure (2) 34Meriem Sari GL à Objet 2 2eme AM GL  Visitor: declares a Visit operation for each class of ConcreteElement .  The operation's name and signature identifies the class that sends the Visit request to the visitor.  ConcreteVisitor: implements each operation declared by Visitor.  Element: defines an Accept operation that takes a visitor as an argument.  ConcreteElement: implements an Accept operation that takes a visitor as an argument.
  • 35. Structure (3) 35Meriem Sari GL à Objet 2 2eme AM GL  Consider two objects: one is called the "element", the other is called the "visitor".  An element has an accept() method that can take the visitor as an argument.  The accept() method calls a visit() method of the visitor.  The element passes itself as an argument to the visit() method.
  • 36. Example (1) 36Meriem Sari GL à Objet 2 2eme AM GL
  • 37. Example (Implementation) 37Meriem Sari GL à Objet 2 2eme AM GL
  • 38. Example (Implementation) 38Meriem Sari GL à Objet 2 2eme AM GL
  • 39. Example (Implementation) 39Meriem Sari GL à Objet 2 2eme AM GL
  • 40. Example (Implementation) 40Meriem Sari GL à Objet 2 2eme AM GL
  • 41. Conclusion 41 If we don't study design patterns in software, we won't be able to improve them, and it'll be harder to come up with new ones. Meriem Sari GL à Objet 2 2eme AM GL
  • 42. Acknowledgment 42 Thank You For Paying Attention Meriem Sari GL à Objet 2 2eme AM GL