SlideShare ist ein Scribd-Unternehmen logo
1 von 21
23
Design Patterns
• Iterators are an example of a design pattern:
– Design pattern = problem + solution in context
– Iterators: solution for providing generic traversals
• Design patterns capture software architectures and
designs
– Not direct code reuse!
– Instead, solution/strategy reuse
– Sometimes, interface reuse
24
Gang of Four
• The book that started it all
• Community refers to
authors as the “Gang of
Four”
• Figures and some text in
these slides come from
book
25
Object Modeling Technique (OMT)
• Used to describe patterns in GO4 book
• Graphical representation of OO relationships
– Class diagrams show the static relationship between
classes
– Object diagrams represent the state of a program as
series of related objects
– Interaction diagrams illustrate execution of the
program as an interaction among related objects
26
Classes
27
Object instantiation
28
Subclassing and Abstract Classes
29
Pseudo-code and Containment
30
Object diagrams
31
Interaction diagrams
time
32
Structure of Iterator (Cursor) Pattern
33
Components of a Pattern
• Name(s)
• Problem
– Context
– Real-world example
• Solution
– Design/structure
– Implementation
• Consequences
• Variations, known uses
34
Iterator Pattern, Again
• Name: Iterator (aka Cursor)
• Problem:
– How to process the elements of an aggregate in an
implementation-independent manner?
• Solution:
– Define an Iterator interface
• next(), hasNext(), etc. methods
– Aggregate returns an instance of an implementation of
Iterator interface to control the iteration
35
Iterator Pattern
• Consequences:
– Support different and simultaneous traversals
• Multiple implementations of Iterator interface
• One traversal per Iterator instance
– Requires coherent policy on aggregate updates
• Invalidate Iterator by throwing an exception, or
• Iterator only considers elements present at the time of its creation
• Variations:
– Internal vs. external iteration
• Java Iterator is external
36
Internal Iterators
public interface InternalIterator<Element> {
void iterate(Processor<Element> p);
}
public interface Processor<Element> {
public void process(Element e);
}
• The internal iterator applies the processor instance to each
element of the aggregate
– Thus, entire traversal happens “at once”
– Less control for client, but easier to formulate traversal
37
Design Patterns: Goals
• To support reuse of successful designs
• To facilitate software evolution
– Add new features easily, without breaking existing ones
• In short, we want to design for change
38
Underlying Principles
• Reduce implementation dependencies between
elements of a software system
• Sub-goals:
– Program to an interface, not an implementation
– Favor composition over inheritance
– Use delegation
39
Program to Interface, Not Implementation
• Rely on abstract classes and interfaces to hide
differences between subclasses from clients
– Interface defines an object’s use (protocol)
– Implementation defines particular policy
• Example: Iterator interface, compared to its
implementation for a LinkedList
40
Rationale
• Decouples clients from the implementations of the
applications they use
• When clients manipulate an interface, they remain
unaware of the specific object types being used.
• Therefore: clients are less dependent on an
implementation, so it can be easily changed later.
41
Favor Composition over Class Inheritance
• White box reuse:
– Inheritance
• Black box reuse:
– Composition
AClass
amethod
BClass
amethod
BClass
amethod
AClass
amethod
aVar
42
Rationale
• White-box reuse results in implementation
dependencies on the parent class
– Reusing a subclass may require rewriting the parent
– But inheritance easy to specify
• Black-box reuse often preferred
– Eliminates implementation dependencies, hides
information, object relationships non-static for better
run-time flexibility
– But adds run-time overhead (additional instance
allocation, communication by dynamic dispatch)
43
Delegation
• Forward messages (delegate) to different instances
at run-time; a form of composition
– May pass invoking object’s this pointer to simulate
inheritance
Rectangle
area()
width
height
Window
area()
rectangle
Return width * height
return rectangle.area()
44
Rationale
• Object relationships dynamic
– Composes or re-composes behavior at run-time
• But:
– Sometimes code harder to read and understand
– Efficiency (because of black-box reuse)
45
Design Patterns Taxonomy
• 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 and distribute responsibility
46
Catalogue of Patterns: Creation Patterns
• Singleton
– Ensure a class only has one instance, and provide a
global point of access to it.
• Typesafe Enum
– Generalizes Singleton: ensures a class has a fixed
number of unique instances.
• Abstract Factory
– Provide an interface for creating families of related or
dependent objects without specifying their concrete
classes.
47
Structural Patterns
• Adapter
– Convert the interface of a class into another interface
clients expect. Adapter lets classes work together that
couldn't otherwise because of incompatible interfaces
• Proxy
– Provide a surrogate or placeholder for another object to
control access to it
• Decorator
– Attach additional responsibilities to an object
dynamically
48
Behavioral Patterns
• Template
– Define the skeleton of an algorithm in an operation,
deferring some steps to subclasses
• State
– Allow an object to alter its behavior when its internal
state changes. The object will appear to change its class
• Observer
– Define a one-to-many dependency between objects so
that when one object changes state, all its dependents
are notified and updated automatically
49
Singleton Objects
• Problem:
– Some classes have conceptually one instance
• Many printers, but only one print spooler
• One file system
• One window manager
– Creating many objects that represent the same
conceptual instance adds complexity and overhead
• Solution: only create one object and reuse it
– Encapsulate the code that manages the reuse
50
The Singleton Solution
• Class is responsible for tracking its sole instance
– Make constructor private
– Provide static method/field to allow access to the only
instance of the class
• Benefit:
– Reuse implies better performance
– Class encapsulates code to ensure reuse of the object;
no need to burden client
51
Singleton pattern
52
Implementing the Singleton method
• In Java, just define a final static field
public class Singleton {
private Singleton() {…}
final private static Singleton instance
= new Singleton();
public static Singleton getInstance()
{ return instance; }
}
• Java semantics guarantee object is created
immediately before first use
53
Marshalling
• Marshalling is the process of transforming
internal data into a form that can be
– Written to disk
– Sent over the network
– Etc.
• Unmarshalling is the inverse process
54
Marhsalling in Java
• Java provides support for marshalling objects
– Classes implement the Serializable interface
– The JVM imlpements standard marhsalling and
unmarshalling automatically
• E.g., enables you to create persistent objects, stored on disk
• This can be useful for building a light-weight database
• Also useful for distributed object systems
• Often, generic implementation works fine
– But let’s consider singletons...
55
Marhsalling and Singletons
• What happens when we unmarshall a singleton?
• Problem: JVM doesn’t know about singletons
– It will create two instances of Singleton.instance!
– Oops!
Singleton.instance Singleton.instance
56
Marhsalling and Singletons (cont’d)
• Solution: Implement
– Object readResolve() throws ObjectStreamException;
• This method will be called after standard unmarshilling
• Returned result is substituted for standard unmarshalled result
• E.g., add to Singleton class the following method
– Object readResolve() { return instance; }
• Notes: Serialization is wacky!
– For example, objects can only be nested 1001 deep????
57
Generalizing Singleton: Typesafe Enum
• Problem:
– Need a number of unique objects, not just one
– Basically want a C-style enumerated type, but safe
• Solution:
– Generalize the Singleton Pattern to keep track of
multiple, unique objects (rather than just one)
58
Typesafe Enum Pattern
Enum
static Enum inst1
static Enum inst2
EnumOp ()
Enum
Enum
EnumOp ()
EnumOp ()
data
data
data
Note: constructor is private
59
Typesafe Enum: Example
public class Suit {
private final String name;
private Suit(String name) { this.name = name; }
public String toString() { return name; }
public static final Suit CLUBS = new Suit(“clubs”);
public static final Suit DIAMONDS = new Suit(“diamonds”);
public static final Suit HEARTS = new Suit(“hearts”);
public static final Suit SPADES = new Suit(“spades”);
}
60
Enumerators in Java 1.5
• New version of Java has type safe enums
– Built-in: Don’t need to use the design pattern
• public enum Suit { CLUBS, DIAMONDS, HEARTS,
SPADES }
– Type checked at compile time
– Implemented as objects (translated as prev slide?)
– Two extra class methods:
• public static <this enum class>[] values() -- the enumeration elts
• public static <this enum class> valueOf(String name) -- get an elt
61
Adapter (aka Wrapper) Pattern
• Problem:
– You have some code you want to use for a program
– You can’t incorporate the code directly (e.g., you just
have the .class file, say as part of a library)
– The code does not have the interface you want
• Different method names
• More or fewer methods than you need
• To use this code, you must adapt it to your
situation
62
Adapter Pattern (cont’d)
• Here’s what we have:
– Client is already written, and it uses the Target interface
– Adaptee has a method that works, but has the wrong
name/interface
• How do we enable the Client to use the Adaptee?
63
Adapter Pattern (cont’d)
• Solution: adapter class to implement client’s
expected interface, forwarding methods

Weitere ähnliche Inhalte

Was ist angesagt?

Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Sagar Verma
 
Artificial neural network for concrete mix design
Artificial neural network for concrete mix designArtificial neural network for concrete mix design
Artificial neural network for concrete mix designMonjurul Shuvo
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Soumen Santra
 
Java tutorials
Java tutorialsJava tutorials
Java tutorialssaryu2011
 
The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptBill Buchan
 
Unit3 part3-packages and interfaces
Unit3 part3-packages and interfacesUnit3 part3-packages and interfaces
Unit3 part3-packages and interfacesDevaKumari Vijay
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to ScalaBrent Lemons
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Sagar Verma
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritanceKalai Selvi
 
02 introductionto java
02 introductionto java02 introductionto java
02 introductionto javaAPU
 

Was ist angesagt? (20)

Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
 
Artificial neural network for concrete mix design
Artificial neural network for concrete mix designArtificial neural network for concrete mix design
Artificial neural network for concrete mix design
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in Lotuscript
 
Metaprogramming ruby
Metaprogramming rubyMetaprogramming ruby
Metaprogramming ruby
 
Neural network and mlp
Neural network and mlpNeural network and mlp
Neural network and mlp
 
Unit3 part3-packages and interfaces
Unit3 part3-packages and interfacesUnit3 part3-packages and interfaces
Unit3 part3-packages and interfaces
 
Unit3 part2-inheritance
Unit3 part2-inheritanceUnit3 part2-inheritance
Unit3 part2-inheritance
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
Java introduction
Java introductionJava introduction
Java introduction
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritance
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
02 introductionto java
02 introductionto java02 introductionto java
02 introductionto java
 

Andere mochten auch

From code to pattern, part one
From code to pattern, part oneFrom code to pattern, part one
From code to pattern, part oneBingfeng Zhao
 
Java8 - Interfaces, evolved
Java8 - Interfaces, evolvedJava8 - Interfaces, evolved
Java8 - Interfaces, evolvedCharles Casadei
 
Modern software development anti patterns (OSCON 2012)
Modern software development anti patterns (OSCON 2012)Modern software development anti patterns (OSCON 2012)
Modern software development anti patterns (OSCON 2012)Martijn Verburg
 
Design patterns illustrated-2015-03
Design patterns illustrated-2015-03Design patterns illustrated-2015-03
Design patterns illustrated-2015-03Herman Peeren
 
Design patterns intro
Design patterns introDesign patterns intro
Design patterns introJean Pаoli
 
The 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryThe 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryachraf_ing
 
Java - Singleton Pattern
Java - Singleton PatternJava - Singleton Pattern
Java - Singleton PatternCharles Casadei
 
eXtreme programming
eXtreme programmingeXtreme programming
eXtreme programmingJean Pаoli
 
The Big Red Book - Panavision
The Big Red Book - PanavisionThe Big Red Book - Panavision
The Big Red Book - PanavisionFanus van Straten
 
Design Anti Patterns - How to Design a Poor Web Experience
Design Anti Patterns - How to Design a Poor Web ExperienceDesign Anti Patterns - How to Design a Poor Web Experience
Design Anti Patterns - How to Design a Poor Web ExperienceBill Scott
 
Domain logic patterns of Software Architecture
Domain logic patterns of Software ArchitectureDomain logic patterns of Software Architecture
Domain logic patterns of Software ArchitectureShweta Ghate
 
Out of box page object design pattern, java
Out of box page object design pattern, javaOut of box page object design pattern, java
Out of box page object design pattern, javaCOMAQA.BY
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan GoleChetan Gole
 

Andere mochten auch (20)

From code to pattern, part one
From code to pattern, part oneFrom code to pattern, part one
From code to pattern, part one
 
Java8 - Interfaces, evolved
Java8 - Interfaces, evolvedJava8 - Interfaces, evolved
Java8 - Interfaces, evolved
 
Go f designpatterns 130116024923-phpapp02
Go f designpatterns 130116024923-phpapp02Go f designpatterns 130116024923-phpapp02
Go f designpatterns 130116024923-phpapp02
 
Patterns go f
Patterns go fPatterns go f
Patterns go f
 
Infostroy 2013
Infostroy 2013Infostroy 2013
Infostroy 2013
 
Modern software development anti patterns (OSCON 2012)
Modern software development anti patterns (OSCON 2012)Modern software development anti patterns (OSCON 2012)
Modern software development anti patterns (OSCON 2012)
 
Design patterns illustrated-2015-03
Design patterns illustrated-2015-03Design patterns illustrated-2015-03
Design patterns illustrated-2015-03
 
Design patterns intro
Design patterns introDesign patterns intro
Design patterns intro
 
The 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryThe 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summary
 
Java - Singleton Pattern
Java - Singleton PatternJava - Singleton Pattern
Java - Singleton Pattern
 
eXtreme programming
eXtreme programmingeXtreme programming
eXtreme programming
 
The Big Red Book - Panavision
The Big Red Book - PanavisionThe Big Red Book - Panavision
The Big Red Book - Panavision
 
Design Anti Patterns - How to Design a Poor Web Experience
Design Anti Patterns - How to Design a Poor Web ExperienceDesign Anti Patterns - How to Design a Poor Web Experience
Design Anti Patterns - How to Design a Poor Web Experience
 
Domain logic patterns of Software Architecture
Domain logic patterns of Software ArchitectureDomain logic patterns of Software Architecture
Domain logic patterns of Software Architecture
 
Anti Patterns
Anti PatternsAnti Patterns
Anti Patterns
 
Design pattern with Java 8
Design pattern with Java 8Design pattern with Java 8
Design pattern with Java 8
 
Out of box page object design pattern, java
Out of box page object design pattern, javaOut of box page object design pattern, java
Out of box page object design pattern, java
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Design patterns
Design patternsDesign patterns
Design patterns
 

Ähnlich wie Design Patterns - GOF

Introduction to Design Patterns in Javascript
Introduction to Design Patterns in JavascriptIntroduction to Design Patterns in Javascript
Introduction to Design Patterns in JavascriptSanthosh Kumar Srinivasan
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptxSachin Patidar
 
8 oo approach&uml-23_feb
8 oo approach&uml-23_feb8 oo approach&uml-23_feb
8 oo approach&uml-23_febRaj Shah
 
Style & Design Principles 02 - Design Patterns
Style & Design Principles 02 - Design PatternsStyle & Design Principles 02 - Design Patterns
Style & Design Principles 02 - Design PatternsNick Pruehs
 
note2_DesignPatterns (1).pptx
note2_DesignPatterns (1).pptxnote2_DesignPatterns (1).pptx
note2_DesignPatterns (1).pptxReemaAsker1
 
Design Pattern
Design PatternDesign Pattern
Design PatternHimanshu
 
Simulation and modeling introduction.pptx
Simulation and modeling introduction.pptxSimulation and modeling introduction.pptx
Simulation and modeling introduction.pptxShamasRehman4
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptRushikeshChikane1
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptRushikeshChikane2
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxanguraju1
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)stanbridge
 
Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0Ganapathi M
 

Ähnlich wie Design Patterns - GOF (20)

Introduction to Design Patterns in Javascript
Introduction to Design Patterns in JavascriptIntroduction to Design Patterns in Javascript
Introduction to Design Patterns in Javascript
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptx
 
8 oo approach&uml-23_feb
8 oo approach&uml-23_feb8 oo approach&uml-23_feb
8 oo approach&uml-23_feb
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Style & Design Principles 02 - Design Patterns
Style & Design Principles 02 - Design PatternsStyle & Design Principles 02 - Design Patterns
Style & Design Principles 02 - Design Patterns
 
note2_DesignPatterns (1).pptx
note2_DesignPatterns (1).pptxnote2_DesignPatterns (1).pptx
note2_DesignPatterns (1).pptx
 
Design Pattern
Design PatternDesign Pattern
Design Pattern
 
Simulation and modeling introduction.pptx
Simulation and modeling introduction.pptxSimulation and modeling introduction.pptx
Simulation and modeling introduction.pptx
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.pptDesign_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.ppt
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
 
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.pptChapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
 
Real-Time Design Patterns
Real-Time Design PatternsReal-Time Design Patterns
Real-Time Design Patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
 
Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0
 

Mehr von Fanus van Straten

Critical water shortages disaster plan summary
Critical water shortages disaster plan summaryCritical water shortages disaster plan summary
Critical water shortages disaster plan summaryFanus van Straten
 
Zinandi Agreement For Service
Zinandi Agreement For ServiceZinandi Agreement For Service
Zinandi Agreement For ServiceFanus van Straten
 
Zinandi Agreement For Service
Zinandi Agreement For ServiceZinandi Agreement For Service
Zinandi Agreement For ServiceFanus van Straten
 
African horse sickness diagnosis - Cape Town, South Africa
African horse sickness diagnosis - Cape Town, South AfricaAfrican horse sickness diagnosis - Cape Town, South Africa
African horse sickness diagnosis - Cape Town, South AfricaFanus van Straten
 
How To Design a Memorable Brand That Catches On
How To Design a Memorable Brand That Catches OnHow To Design a Memorable Brand That Catches On
How To Design a Memorable Brand That Catches OnFanus van Straten
 
Position Statement on the Use of Dominance Theory in Behavior Modification of...
Position Statement on the Use of Dominance Theory in Behavior Modification of...Position Statement on the Use of Dominance Theory in Behavior Modification of...
Position Statement on the Use of Dominance Theory in Behavior Modification of...Fanus van Straten
 
Fanus van Straten CV / Resume
Fanus van Straten CV / ResumeFanus van Straten CV / Resume
Fanus van Straten CV / ResumeFanus van Straten
 
The A to Z of Adobe Illustrator – design & illustration
The A to Z of Adobe Illustrator – design & illustrationThe A to Z of Adobe Illustrator – design & illustration
The A to Z of Adobe Illustrator – design & illustrationFanus van Straten
 
Telkom Internet Acceptable Use Policy AUP
Telkom Internet Acceptable Use Policy AUPTelkom Internet Acceptable Use Policy AUP
Telkom Internet Acceptable Use Policy AUPFanus van Straten
 
Periodic table guide to seo - Search Engine Land
Periodic table guide to seo - Search Engine LandPeriodic table guide to seo - Search Engine Land
Periodic table guide to seo - Search Engine LandFanus van Straten
 
Adobe Illustrator CS5 Keyboard Shortcuts
Adobe Illustrator CS5 Keyboard Shortcuts Adobe Illustrator CS5 Keyboard Shortcuts
Adobe Illustrator CS5 Keyboard Shortcuts Fanus van Straten
 
Windows 8.1 Preview Product Guide
Windows 8.1 Preview Product GuideWindows 8.1 Preview Product Guide
Windows 8.1 Preview Product GuideFanus van Straten
 
Portable massage tables, beds & accessories - Cape Town
Portable massage tables, beds & accessories - Cape TownPortable massage tables, beds & accessories - Cape Town
Portable massage tables, beds & accessories - Cape TownFanus van Straten
 
Recreate Original McDonald’s Menu Items at Home
Recreate Original McDonald’s Menu Items at HomeRecreate Original McDonald’s Menu Items at Home
Recreate Original McDonald’s Menu Items at HomeFanus van Straten
 
Lekker Outydse Afrikaanse Resepte
Lekker Outydse Afrikaanse ResepteLekker Outydse Afrikaanse Resepte
Lekker Outydse Afrikaanse ResepteFanus van Straten
 

Mehr von Fanus van Straten (20)

AMSHeR Progress Report
AMSHeR Progress ReportAMSHeR Progress Report
AMSHeR Progress Report
 
Critical water shortages disaster plan summary
Critical water shortages disaster plan summaryCritical water shortages disaster plan summary
Critical water shortages disaster plan summary
 
Cryodesalination
CryodesalinationCryodesalination
Cryodesalination
 
Video Arts Essentials
Video Arts EssentialsVideo Arts Essentials
Video Arts Essentials
 
Zinandi Agreement For Service
Zinandi Agreement For ServiceZinandi Agreement For Service
Zinandi Agreement For Service
 
Zinandi Agreement For Service
Zinandi Agreement For ServiceZinandi Agreement For Service
Zinandi Agreement For Service
 
African horse sickness diagnosis - Cape Town, South Africa
African horse sickness diagnosis - Cape Town, South AfricaAfrican horse sickness diagnosis - Cape Town, South Africa
African horse sickness diagnosis - Cape Town, South Africa
 
How To Design a Memorable Brand That Catches On
How To Design a Memorable Brand That Catches OnHow To Design a Memorable Brand That Catches On
How To Design a Memorable Brand That Catches On
 
Position Statement on the Use of Dominance Theory in Behavior Modification of...
Position Statement on the Use of Dominance Theory in Behavior Modification of...Position Statement on the Use of Dominance Theory in Behavior Modification of...
Position Statement on the Use of Dominance Theory in Behavior Modification of...
 
EBA Corporate Proposal
EBA Corporate ProposalEBA Corporate Proposal
EBA Corporate Proposal
 
Fanus van Straten CV / Resume
Fanus van Straten CV / ResumeFanus van Straten CV / Resume
Fanus van Straten CV / Resume
 
The A to Z of Adobe Illustrator – design & illustration
The A to Z of Adobe Illustrator – design & illustrationThe A to Z of Adobe Illustrator – design & illustration
The A to Z of Adobe Illustrator – design & illustration
 
Telkom Internet Acceptable Use Policy AUP
Telkom Internet Acceptable Use Policy AUPTelkom Internet Acceptable Use Policy AUP
Telkom Internet Acceptable Use Policy AUP
 
Periodic table guide to seo - Search Engine Land
Periodic table guide to seo - Search Engine LandPeriodic table guide to seo - Search Engine Land
Periodic table guide to seo - Search Engine Land
 
Adobe Illustrator CS5 Keyboard Shortcuts
Adobe Illustrator CS5 Keyboard Shortcuts Adobe Illustrator CS5 Keyboard Shortcuts
Adobe Illustrator CS5 Keyboard Shortcuts
 
Windows 8.1 Preview Product Guide
Windows 8.1 Preview Product GuideWindows 8.1 Preview Product Guide
Windows 8.1 Preview Product Guide
 
Portable massage tables, beds & accessories - Cape Town
Portable massage tables, beds & accessories - Cape TownPortable massage tables, beds & accessories - Cape Town
Portable massage tables, beds & accessories - Cape Town
 
Recreate Original McDonald’s Menu Items at Home
Recreate Original McDonald’s Menu Items at HomeRecreate Original McDonald’s Menu Items at Home
Recreate Original McDonald’s Menu Items at Home
 
Begin jou eie besigheid
Begin jou eie besigheidBegin jou eie besigheid
Begin jou eie besigheid
 
Lekker Outydse Afrikaanse Resepte
Lekker Outydse Afrikaanse ResepteLekker Outydse Afrikaanse Resepte
Lekker Outydse Afrikaanse Resepte
 

Kürzlich hochgeladen

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Kürzlich hochgeladen (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Design Patterns - GOF

  • 1. 23 Design Patterns • Iterators are an example of a design pattern: – Design pattern = problem + solution in context – Iterators: solution for providing generic traversals • Design patterns capture software architectures and designs – Not direct code reuse! – Instead, solution/strategy reuse – Sometimes, interface reuse 24 Gang of Four • The book that started it all • Community refers to authors as the “Gang of Four” • Figures and some text in these slides come from book
  • 2. 25 Object Modeling Technique (OMT) • Used to describe patterns in GO4 book • Graphical representation of OO relationships – Class diagrams show the static relationship between classes – Object diagrams represent the state of a program as series of related objects – Interaction diagrams illustrate execution of the program as an interaction among related objects 26 Classes
  • 6. 33 Components of a Pattern • Name(s) • Problem – Context – Real-world example • Solution – Design/structure – Implementation • Consequences • Variations, known uses 34 Iterator Pattern, Again • Name: Iterator (aka Cursor) • Problem: – How to process the elements of an aggregate in an implementation-independent manner? • Solution: – Define an Iterator interface • next(), hasNext(), etc. methods – Aggregate returns an instance of an implementation of Iterator interface to control the iteration
  • 7. 35 Iterator Pattern • Consequences: – Support different and simultaneous traversals • Multiple implementations of Iterator interface • One traversal per Iterator instance – Requires coherent policy on aggregate updates • Invalidate Iterator by throwing an exception, or • Iterator only considers elements present at the time of its creation • Variations: – Internal vs. external iteration • Java Iterator is external 36 Internal Iterators public interface InternalIterator<Element> { void iterate(Processor<Element> p); } public interface Processor<Element> { public void process(Element e); } • The internal iterator applies the processor instance to each element of the aggregate – Thus, entire traversal happens “at once” – Less control for client, but easier to formulate traversal
  • 8. 37 Design Patterns: Goals • To support reuse of successful designs • To facilitate software evolution – Add new features easily, without breaking existing ones • In short, we want to design for change 38 Underlying Principles • Reduce implementation dependencies between elements of a software system • Sub-goals: – Program to an interface, not an implementation – Favor composition over inheritance – Use delegation
  • 9. 39 Program to Interface, Not Implementation • Rely on abstract classes and interfaces to hide differences between subclasses from clients – Interface defines an object’s use (protocol) – Implementation defines particular policy • Example: Iterator interface, compared to its implementation for a LinkedList 40 Rationale • Decouples clients from the implementations of the applications they use • When clients manipulate an interface, they remain unaware of the specific object types being used. • Therefore: clients are less dependent on an implementation, so it can be easily changed later.
  • 10. 41 Favor Composition over Class Inheritance • White box reuse: – Inheritance • Black box reuse: – Composition AClass amethod BClass amethod BClass amethod AClass amethod aVar 42 Rationale • White-box reuse results in implementation dependencies on the parent class – Reusing a subclass may require rewriting the parent – But inheritance easy to specify • Black-box reuse often preferred – Eliminates implementation dependencies, hides information, object relationships non-static for better run-time flexibility – But adds run-time overhead (additional instance allocation, communication by dynamic dispatch)
  • 11. 43 Delegation • Forward messages (delegate) to different instances at run-time; a form of composition – May pass invoking object’s this pointer to simulate inheritance Rectangle area() width height Window area() rectangle Return width * height return rectangle.area() 44 Rationale • Object relationships dynamic – Composes or re-composes behavior at run-time • But: – Sometimes code harder to read and understand – Efficiency (because of black-box reuse)
  • 12. 45 Design Patterns Taxonomy • 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 and distribute responsibility 46 Catalogue of Patterns: Creation Patterns • Singleton – Ensure a class only has one instance, and provide a global point of access to it. • Typesafe Enum – Generalizes Singleton: ensures a class has a fixed number of unique instances. • Abstract Factory – Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
  • 13. 47 Structural Patterns • Adapter – Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces • Proxy – Provide a surrogate or placeholder for another object to control access to it • Decorator – Attach additional responsibilities to an object dynamically 48 Behavioral Patterns • Template – Define the skeleton of an algorithm in an operation, deferring some steps to subclasses • State – Allow an object to alter its behavior when its internal state changes. The object will appear to change its class • Observer – Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically
  • 14. 49 Singleton Objects • Problem: – Some classes have conceptually one instance • Many printers, but only one print spooler • One file system • One window manager – Creating many objects that represent the same conceptual instance adds complexity and overhead • Solution: only create one object and reuse it – Encapsulate the code that manages the reuse 50 The Singleton Solution • Class is responsible for tracking its sole instance – Make constructor private – Provide static method/field to allow access to the only instance of the class • Benefit: – Reuse implies better performance – Class encapsulates code to ensure reuse of the object; no need to burden client
  • 15. 51 Singleton pattern 52 Implementing the Singleton method • In Java, just define a final static field public class Singleton { private Singleton() {…} final private static Singleton instance = new Singleton(); public static Singleton getInstance() { return instance; } } • Java semantics guarantee object is created immediately before first use
  • 16. 53 Marshalling • Marshalling is the process of transforming internal data into a form that can be – Written to disk – Sent over the network – Etc. • Unmarshalling is the inverse process 54 Marhsalling in Java • Java provides support for marshalling objects – Classes implement the Serializable interface – The JVM imlpements standard marhsalling and unmarshalling automatically • E.g., enables you to create persistent objects, stored on disk • This can be useful for building a light-weight database • Also useful for distributed object systems • Often, generic implementation works fine – But let’s consider singletons...
  • 17. 55 Marhsalling and Singletons • What happens when we unmarshall a singleton? • Problem: JVM doesn’t know about singletons – It will create two instances of Singleton.instance! – Oops! Singleton.instance Singleton.instance 56 Marhsalling and Singletons (cont’d) • Solution: Implement – Object readResolve() throws ObjectStreamException; • This method will be called after standard unmarshilling • Returned result is substituted for standard unmarshalled result • E.g., add to Singleton class the following method – Object readResolve() { return instance; } • Notes: Serialization is wacky! – For example, objects can only be nested 1001 deep????
  • 18. 57 Generalizing Singleton: Typesafe Enum • Problem: – Need a number of unique objects, not just one – Basically want a C-style enumerated type, but safe • Solution: – Generalize the Singleton Pattern to keep track of multiple, unique objects (rather than just one) 58 Typesafe Enum Pattern Enum static Enum inst1 static Enum inst2 EnumOp () Enum Enum EnumOp () EnumOp () data data data Note: constructor is private
  • 19. 59 Typesafe Enum: Example public class Suit { private final String name; private Suit(String name) { this.name = name; } public String toString() { return name; } public static final Suit CLUBS = new Suit(“clubs”); public static final Suit DIAMONDS = new Suit(“diamonds”); public static final Suit HEARTS = new Suit(“hearts”); public static final Suit SPADES = new Suit(“spades”); } 60 Enumerators in Java 1.5 • New version of Java has type safe enums – Built-in: Don’t need to use the design pattern • public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES } – Type checked at compile time – Implemented as objects (translated as prev slide?) – Two extra class methods: • public static <this enum class>[] values() -- the enumeration elts • public static <this enum class> valueOf(String name) -- get an elt
  • 20. 61 Adapter (aka Wrapper) Pattern • Problem: – You have some code you want to use for a program – You can’t incorporate the code directly (e.g., you just have the .class file, say as part of a library) – The code does not have the interface you want • Different method names • More or fewer methods than you need • To use this code, you must adapt it to your situation 62 Adapter Pattern (cont’d) • Here’s what we have: – Client is already written, and it uses the Target interface – Adaptee has a method that works, but has the wrong name/interface • How do we enable the Client to use the Adaptee?
  • 21. 63 Adapter Pattern (cont’d) • Solution: adapter class to implement client’s expected interface, forwarding methods