SlideShare a Scribd company logo
1 of 58
Download to read offline
Introduction Summary References
DESIGN PATTERNS
Muhammad Adil Raja
Roaming Researchers, Inc.
cbna
January 29, 2017
Introduction Summary References
OUTLINE I
1 INTRODUCTION
2 SUMMARY
3 REFERENCES
Introduction Summary References
INTRODUCTION
When faced with a new problem, where do you look for
inspiration?
Most people look to solutions of previous problems that
have similar characteristics.
This insight is what is behind design patterns; collections
of proven ways to structure the relationships between
objects in the pursuit of a given objective.
Introduction Summary References
INSPIRATION
Design patterns speed the process of finding a solution, by
eliminating the need to reinvent well-known and proven
solutions.
Just as important, design patterns provide a vocabulary
with which to discuss the space of possible design choices.
This vocabulary is termed a pattern language.
Introduction Summary References
TYPES OF DESIGN PATTERNS
Creational: Patterns provide instantiation mechanisms,
making it easier to create objects in a way that suits the
situation.
Structural: Patterns generally deal with relationships
between entities, making it easier for these entities to work
together.
Behavioral: Patterns are used in communications
between entities and make it easier and more flexible for
these entities to communicate.
Introduction Summary References
BENEFITS OF USING DESIGN PATTERNS
Analogy from civil engineering.
Question: What will a civil engineer do when confronted
with a problem to cross a river?
Answer: Build a tunnel or a bridge.
Question: How about preventing rain from entering a
window?
Answer: Build a canopy.
They give the developer a selection of tried and tested
solutions to work with.
They are language neutral and so can be applied to any
language that supports object-orientation.
They aid communication by the very fact that they are well
documented and can be researched if that is not the case.
They have a proven track record as they are already widely
used and thus reduce the technical risk to the project.
They are highly flexible and can be used in practically any
Introduction Summary References
RELATIONSHIP TO DEPENDENCY AND VISIBILITY
Many patterns are involved with the concepts of
dependency we introduced in the previous chapter.
Determining where strong dependencies are necessary,
and how to weaken dependencies whenever possible.
Introduction Summary References
A SIMPLE EXAMPLE, THE ADAPTER
An adaptor is used to connect a client (an object that
needs a service) with a server (an object that provides the
service).
The client requires a certain interface, and while the server
provides the necessary functionality, it does not support
the interface.
The adapter changes the interface, without actually doing
the work.
Introduction Summary References
AN EXAMPLE ADAPTER
EXAMPLE
class MyCollection implements Collection {
public boolean isEmpty ( )
{ return data . count ( ) == 0; }
public int size ( )
{ return data . count ( ) ; }
public void addElement ( Object newElement )
{ data . add ( newElement ) ; }
public boolean containsElement ( Object t e s t )
{ return data . f i n d ( t e s t ) != n u l l ; }
public Object findElement ( Object t e s t )
{ return data . f i n d ( t e s t ) ; }
private DataBox data = new DataBox ( ) ;
}
Example
DataBox is some collection that does not support the
Collection interface.
Adapters are often needed to connect software from
Introduction Summary References
DESCRIBING PATTERNS
Patterns themselves have developed their own vocabulary for
description:
NAME: Contributes to the pattern vocabulary.
SYNOPSIS: Short description of the problem the pattern will
solve.
FORCES: Requirements, considerations, or necessary
conditions
SOLUTION: The essense of the solution
COUNTERFORCES: Reasons for not using the pattern.
RELATED PATTERNS: Possible alternatives in the design.
Introduction Summary References
EXAMPLE PATTERNS
We will briefly examine a number of common patterns:
Iterator.
Software Factory.
Strategy.
Singleton.
Composite.
Decorator.
Double-Dispatch.
Flyweight.
Proxy.
Facade.
Observer.
Introduction Summary References
ITERATOR
Problem: How do you provide a client access to elements
in a collection, without exposing the structure of the
collection.
Solution: Allow clients to manipulate an object that can
return the current value and move to the next element in
the collection.
Example, Enumerators in Java.
EXAMPLE
interface Enumerator {
public boolean hasMoreElements ( ) ;
public Object nextElement ( ) ;
}
Enumeator e = . . . ;
while ( e . hasMoreElements ) {
Object val = e . nextElement ( ) ;
. . .
}
Introduction Summary References
SOFTWARE FACTORY
INTRODUCTION
Problem: How do you simplify the manipulation of many
different implementations of the same interface (i.e.,
iterators).
Solution: Hide creation within a method, have the method
declare a return type that is more general than its actual
return type.
EXAMPLE
class SortedList {
. . .
Enumerator elements ( ) { return new SortedListEnumerator ( ) ; }
. . .
private class SortedListEnumerator implements Enumerator {
. . .
}
}
Introduction Summary References
SOFTWARE FACTORY
The method is the “factory” in the name. Users don’t need
to know the exact type the factory returns, only the
declared type.
The factory could even return different types, depending
upon circumstances.
Introduction Summary References
SOFTWARE FACTORY
ANOTHER EXAMPLE
FIGURE: Factory
Introduction Summary References
SOFTWARE FACTORY
STEP 1: CREATE AN INTERFACE.
SHAPE
public interface Shape {
void draw ( ) ;
}
Introduction Summary References
SOFTWARE FACTORY
STEP 2: CREATE CONCRETE CLASSES IMPLEMENTING THE SAME INTERFACE.
RECTANGLE
public class Rectangle implements Shape {
@Override
public void draw ( ) {
System . out . p r i n t l n ( " Inside Rectangle : : draw ( ) method . " ) ;
}
}
SQUARE
public class Square implements Shape {
@Override
public void draw ( ) {
System . out . p r i n t l n ( " Inside Square : : draw ( ) method . " ) ;
}
}
Introduction Summary References
SOFTWARE FACTORY
CIRCLE
public class Circle implements Shape {
@Override
public void draw ( ) {
System . out . p r i n t l n ( " Inside Circle : : draw ( ) method . " ) ;
}
}
Introduction Summary References
SOFTWARE FACTORY
STEP 3: CREATE A FACTORY TO GENERATE OBJECT OF CONCRETE CLASS BASED ON GIVEN
INFORMATION.
SHAPEFACTORY
public class ShapeFactory {
/ / use getShape method to get object of type shape
public Shape getShape ( String shapeType ) {
i f ( shapeType == null ) {
return null ;
}
i f ( shapeType . equalsIgnoreCase ( "CIRCLE" ) ) {
return new Circle ( ) ;
} else i f ( shapeType . equalsIgnoreCase ( "RECTANGLE" ) ) {
return new Rectangle ( ) ;
} else i f ( shapeType . equalsIgnoreCase ( "SQUARE" ) ) {
return new Square ( ) ;
}
return null ;
}
}
Introduction Summary References
SOFTWARE FACTORY
STEP 4: USE THE FACTORY TO GET OBJECT OF CONCRETE CLASS BY PASSING AN
INFORMATION SUCH AS TYPE.
FACTORY PATTERN DEMO
public class FactoryPatternDemo {
public static void main ( String [ ] args ) {
ShapeFactory shapeFactory = new ShapeFactory ( ) ;
/ / get an object of Circle and c a l l i t s draw method .
Shape shape1 = shapeFactory . getShape ( "CIRCLE" ) ;
/ / c a l l draw method of Circle
shape1 . draw ( ) ;
/ / get an object of Rectangle and c a l l i t s draw method .
Shape shape2 = shapeFactory . getShape ( "RECTANGLE" ) ;
/ / c a l l draw method of Rectangle
shape2 . draw ( ) ;
/ / get an object of Square and c a l l i t s draw method .
Shape shape3 = shapeFactory . getShape ( "SQUARE" ) ;
/ / c a l l draw method of c i r c l e
shape3 . draw ( ) ;
}
}
Introduction Summary References
SOFTWARE FACTORY
STEP 5: VERIFY THE OUTPUT.
FACTORY PATTERN DEMO
Inside Circle::draw() method.
Inside Rectangle::draw() method.
Inside Square::draw() method.
Introduction Summary References
STRATEGY
Problem: Allow the client the choice of many alternatives,
but each is complex, and you don’t want to include code for
all.
Solution: Make many implementations of the same
interface, and allow the client to select one and give it back
to you.
Example: The layout managers in the AWT.
Several different layout managers are implemented, and
the designer selects and creates one.
Gives the designer flexibility, keeps the code size down.
Introduction Summary References
STRATEGY
AN EXAMPLE
FIGURE: Strategy
Introduction Summary References
STRATEGY
STEP 1: CREATE AN INTERFACE.
STRATEGY
public interface Strategy {
public int doOperation ( int num1, int num2 ) ;
}
Introduction Summary References
STRATEGY
STEP 2: CREATE CONCRETE CLASSES IMPLEMENTING THE SAME INTERFACE.
OPERATION ADD
public class OperationAdd implements Strategy {
@Override
public int doOperation ( int num1, int num2) {
return num1 + num2;
}
}
OPERATION SUBTRACT
public class OperationSubstract implements Strategy {
@Override
public int doOperation ( int num1, int num2) {
return num1 − num2;
}
}
Introduction Summary References
STRATEGY
OPERATION MULTIPLY
public class OperationMultiply implements Strategy {
@Override
public int doOperation ( int num1, int num2) {
return num1 ∗ num2;
}
}
Introduction Summary References
STRATEGY
STEP 3: CREATE CONTEXT CLASS.
CONTEXT
public class Context {
private Strategy strategy ;
public Context ( Strategy strategy ) {
this . strategy = strategy ;
}
public int executeStrategy ( int num1, int num2 ) {
return strategy . doOperation (num1, num2 ) ;
}
}
Introduction Summary References
STRATEGY
STEP 4: USE THE CONTEXT TO SEE CHANGE IN BEHAVIOUR WHEN IT CHANGES ITS
STRATEGY.
STRATEGY PATTERN DEMO
public class StrategyPatternDemo {
public static void main ( String [ ] args ) {
Context context = new Context (new OperationAdd ( ) ) ;
System . out . p r i n t l n ( " 10 + 5 = " + context . executeStrategy (10 , 5 ) ) ;
context = new Context (new OperationSubstract ( ) ) ;
System . out . p r i n t l n ( " 10 − 5 = " + context . executeStrategy (10 , 5 ) ) ;
context = new Context (new OperationMultiply ( ) ) ;
System . out . p r i n t l n ( " 10 ∗ 5 = " + context . executeStrategy (10 , 5 ) ) ;
}
}
Introduction Summary References
STRATEGY
STEP 5: VERIFY THE OUTPUT.
FACTORY PATTERN DEMO
10 + 5 = 15
10 - 5 = 5
10 * 5 = 50
Introduction Summary References
SINGLETON
Problem: You want to ensure that there is never more than
one instace of a given class.
Solution: Make the constructor private, have a method that
returns just one instance, which is held inside the class
itself.
EXAMPLE
class SingletonClass {
public :
static SingletonClass ∗ oneAndOnly ( ) { return theOne ; }
private :
static SingletonClass ∗ theOne ;
SingletonClass ( ) { . . . }
} ;
/ / s t a t i c i n i t i a l i z a t i o n
SingletonClass ∗ SingletonClass : : theOne = new SingletonClass ( ) ;
Introduction Summary References
COMPOSITE
Problem: How do you facilitate creation of complex
systems from simple parts?
Solution: Provide a few simple components, and a system
to compose components (simple or otherwise) into new
components.
Regular expressions are an example, are type systems, or
the nesting of panels within panels in the Java AWT API.
Introduction Summary References
COMPOSITE
AN EXAMPLE
FIGURE: Composite
Introduction Summary References
COMPOSITE
STEP 1: CREATE EMPLOYEE CLASS HAVING LIST OF EMPLOYEE OBJECTS.
EMPLOYEE
import java . u t i l . ArrayList ;
import java . u t i l . L i s t ;
public class Employee {
private String name;
private String dept ;
private int salary ;
private List <Employee> subordinates ;
/ / constructor
public Employee ( String name, String dept , int sal ) {
this .name = name;
this . dept = dept ;
this . salary = sal ;
subordinates = new ArrayList <Employee > ( ) ;
}
public void add ( Employee e ) {
subordinates . add ( e ) ;
}
public void remove ( Employee e ) {
subordinates . remove ( e ) ;
}
public List <Employee> getSubordinates ( ) {
Introduction Summary References
COMPOSITE
STEP 2: USE THE EMPLOYEE CLASS TO CREATE AND PRINT EMPLOYEE HIERARCHY.
COMPOSITE PATTERN DEMO
public class CompositePatternDemo {
public static void main ( String [ ] args ) {
Employee CEO = new Employee ( " John " , "CEO" , 30000);
Employee headSales = new Employee ( " Robert " , "Head Sales " , 20000);
Employee headMarketing = new Employee ( " Michel " , "Head Marketing " , 20000);
Employee clerk1 = new Employee ( " Laura " , " Marketing " , 10000);
Employee clerk2 = new Employee ( "Bob" , " Marketing " , 10000);
Employee salesExecutive1 = new Employee ( " Richard " , " Sales " , 10000);
Employee salesExecutive2 = new Employee ( "Rob" , " Sales " , 10000);
CEO. add ( headSales ) ;
CEO. add ( headMarketing ) ;
headSales . add ( salesExecutive1 ) ;
headSales . add ( salesExecutive2 ) ;
headMarketing . add ( clerk1 ) ;
headMarketing . add ( clerk2 ) ;
/ / p r i n t a l l employees of the organization
System . out . p r i n t l n (CEO) ;
Introduction Summary References
DECORATOR I
Filter, wrapper.
Problem: Allow functionally to be layered around an
abstraction, but still dynamically changeable.
Solution: Combine inheritance and composition.
By making an object that both subclasses from another
class and holds an instance of the class, can add new
behaviour while referring all other behaviour to the original
class.
Example Input Streams in the Java I/O System.
Introduction Summary References
DECORATOR II
EXAMPLE
/ / a buffered input stream is−an input stream
class BufferedInputStream extends InputStream {
public BufferedInputStream ( InputStream s ) { data = s ; }
. . .
/ / and a buffered input stream has−an input stream
private InputStream data ;
}
An instance of BufferedInputStream can wrap around any other
type of InputStream, and simply adds a little bit new
functionality.
Introduction Summary References
DOUBLE DISPATCH (MULTIPLE POLYMORPHISM) I
Problem: You have variation in two or more polymorphic
variables.
Solution: Make each a receiver in turn, each message ties
down one source of variation.
Example, suppose we have a hierarchy of Shapes
(Triangle, Square) and Device (Printer, Terminal).
Two variables, one a Shape and one a Device.
First, pass a message to the device, passing the shape as
argument:
Introduction Summary References
DOUBLE DISPATCH (MULTIPLE POLYMORPHISM) II
EXAMPLE
Shape aShape = . . . ;
Device aDevice = . . . ;
aDevice . display ( aShape ) ;
function P r i n t e r . display ( Shape aShape )
begin
aShape . displayOnPrinter ( s e l f ) ;
end ;
function Terminal . display ( Shape aShape )
begin
aShape . displayOnTerminal ( s e l f ) ;
end ;
One message fixes the device, but how to fix the shape?
Each subclass of Shape must implement methods for each
output device:
Introduction Summary References
DOUBLE DISPATCH (MULTIPLE POLYMORPHISM) III
EXAMPLE
class Triangle : public Shape {
public :
Triangle ( Point , Point , Point ) ;
/ / . . .
v i r t u a l void displayOnPrinter ( P r i n t e r ) ;
v i r t u a l void displayOnTerminal ( Terminal ) ;
/ / . . .
private :
Point p1 , p2 , p3 ;
} ;
void Triangle . displayOnPrinter ( P r i n t e r p ) {
/ / p r i n t e r−s p e c i f i c code to
/ / display t r i a n g l e
/ / . . .
}
void Triangle . displayOnTerminal ( Terminal t ) {
/ / terminal−s p e c i f i c code to
/ / display t r i a n g l e
/ / . . .
}
Introduction Summary References
PROXY
Problem: How to hide unimportant communication details,
such as a network, from the client.
Solution: A proxy uses the interface that the client expects,
but passes messages over the network to the server, gets
back the response, and passes it to the client.
The client is therefore hidden from the network details.
FIGURE: Proxy
Similar in some ways to adaptor, but here the intermediary and
the server can have the same interface.
Introduction Summary References
PROXY
AN EXAMPLE
FIGURE: Proxy
Introduction Summary References
PROXY
STEP 1: CREATE AN INTERFACE.
IMAGE
public interface Image {
void display ( ) ;
}
Introduction Summary References
PROXY
STEP 2: CREATE CONCRETE CLASSES IMPLEMENTING THE SAME INTERFACE.
REAL IMAGE
public class RealImage implements Image {
private String fileName ;
public RealImage ( String fileName ) {
this . fileName = fileName ;
loadFromDisk ( fileName ) ;
}
@Override
public void display ( ) {
System . out . p r i n t l n ( " Displaying " + fileName ) ;
}
private void loadFromDisk ( String fileName ) {
System . out . p r i n t l n ( " Loading " + fileName ) ;
}
}
Introduction Summary References
PROXY
PROXY IMAGE
public class ProxyImage implements Image {
private RealImage realImage ;
private String fileName ;
public ProxyImage ( String fileName ) {
this . fileName = fileName ;
}
@Override
public void display ( ) {
i f ( realImage == null ) {
realImage = new RealImage ( fileName ) ;
}
realImage . display ( ) ;
}
}
Introduction Summary References
PROXY
STEP 3: USE THE PROXYIMAGE TO GET OBJECT OF REALIMAGE CLASS WHEN REQUIRED.
PROXY PATTERN DEMO
public class ProxyPatternDemo {
public static void main ( String [ ] args ) {
Image image = new ProxyImage ( " test_10mb . jpg " ) ;
/ / image w i l l be loaded from disk
image . display ( ) ;
System . out . p r i n t l n ( " " ) ;
/ / image w i l l not be loaded from disk
image . display ( ) ;
}
}
Introduction Summary References
PROXY
STEP 4: VERIFY THE OUTPUT.
FACTORY PATTERN DEMO
Loading test_10mb.jpg
Displaying test_10mb.jpg
Displaying test_10mb.jpg
Introduction Summary References
FACADE
Problem: Actual work is performed by two or more objects,
but you want to hide this level of complexity from the client.
Solution: Create a facade object that receives the
messages, but passes commands on to the workers for
completion.
FIGURE: Facade
Also similar to adapter and proxy.
Introduction Summary References
FACADE
ANOTHER EXAMPLE
FIGURE: Facade
Introduction Summary References
FACADE
STEP 1: CREATE AN INTERFACE.
SHAPE
public interface Shape {
void draw ( ) ;
}
Introduction Summary References
FACADE
STEP 2: CREATE CONCRETE CLASSES IMPLEMENTING THE SAME INTERFACE.
RECTANGLE
public class Rectangle implements Shape {
@Override
public void draw ( ) {
System . out . p r i n t l n ( " Inside Rectangle : : draw ( ) method . " ) ;
}
}
SQUARE
public class Square implements Shape {
@Override
public void draw ( ) {
System . out . p r i n t l n ( " Inside Square : : draw ( ) method . " ) ;
}
}
Introduction Summary References
FACADE
CIRCLE
public class Circle implements Shape {
@Override
public void draw ( ) {
System . out . p r i n t l n ( " Inside Circle : : draw ( ) method . " ) ;
}
}
Introduction Summary References
FACADE
STEP 3: CREATE A FACADE CLASS.
SHAPE MAKER
public class ShapeMaker {
private Shape c i r c l e ;
private Shape rectangle ;
private Shape square ;
public ShapeMaker ( ) {
c i r c l e = new Circle ( ) ;
rectangle = new Rectangle ( ) ;
square = new Square ( ) ;
}
public void drawCircle ( ) {
c i r c l e . draw ( ) ;
}
public void drawRectangle ( ) {
rectangle . draw ( ) ;
}
public void drawSquare ( ) {
square . draw ( ) ;
}
}
Introduction Summary References
FACADE
STEP 4: USE THE FACADE TO DRAW VARIOUS TYPES OF SHAPES.
FACADE PATTERN DEMO
public class FacadePatternDemo {
public static void main ( String [ ] args ) {
ShapeMaker shapeMaker = new ShapeMaker ( ) ;
shapeMaker . drawCircle ( ) ;
shapeMaker . drawRectangle ( ) ;
shapeMaker . drawSquare ( ) ;
}
}
Introduction Summary References
FACADE
STEP 5: VERIFY THE OUTPUT.
FACADE PATTERN OUTPUT
Inside Circle::draw() method.
Inside Rectangle::draw() method.
Inside Square::draw() method.
Introduction Summary References
OBSERVER
Problem: How do you dynamically (at run time) add and
remove connections between objects.
Solution: An Observer Manager implements the following
protocol:
“I Want to Observe X” – the OM will keep track of who is
watching who.
“Tell Everybody who is Observing Met that I have
Changed” – the OM can then tell everybody that an object
has changed.
In this way neither the observer nor the observed object
need know the existance of the other.
Introduction Summary References
PATTERNS AND FRAMEWORKS
Both are ways of describing and documenting solutions to
common problems.
Frameworks are more “shrinkwrapped”, ready for
immediate use.
Patterns are more abstract – many patterns are involved in
the solution of one problem.
Introduction Summary References
SUMMARY
In this chapter we have examined a variety of topics
related to dependency.
How classes and objects can depend upon each other.
How methods within a class can depend upon each other.
How to control visibility, as a means of controlling
dependency.
How strong dependency can be weakened by using
alternative designs.
Introduction Summary References
REFERENCES
Images and content for developing these slides have been
taken from the follwoing book with the permission of the
author.
An Introduction to Object Oriented Programming, Timothy
A. Budd.
Some examples and text has been used from Tutsplus.
Some examples have been taken from Tutorialspoint.
Code Project.
This presentation is developed with Beamer:
Darmstadt, crane.

More Related Content

What's hot

27418524 design-patterns-dot-net-with-examples
27418524 design-patterns-dot-net-with-examples27418524 design-patterns-dot-net-with-examples
27418524 design-patterns-dot-net-with-examplesQuang Suma
 
Behavioral Design Patterns
Behavioral Design PatternsBehavioral Design Patterns
Behavioral Design PatternsLidan Hifi
 
Esoteric LINQ and Structural Madness
Esoteric LINQ and Structural MadnessEsoteric LINQ and Structural Madness
Esoteric LINQ and Structural MadnessChris Eargle
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstractionIntro C# Book
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#SyedUmairAli9
 
Functional Effects - Part 1
Functional Effects - Part 1Functional Effects - Part 1
Functional Effects - Part 1Philip Schwarz
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern11prasoon
 
Functional Effects - Part 2
Functional Effects - Part 2Functional Effects - Part 2
Functional Effects - Part 2Philip Schwarz
 
Assignment 7
Assignment 7Assignment 7
Assignment 7IIUM
 
Sofwear deasign and need of design pattern
Sofwear deasign and need of design patternSofwear deasign and need of design pattern
Sofwear deasign and need of design patternchetankane
 
On Vector Functions With A Parameter
On Vector Functions With A ParameterOn Vector Functions With A Parameter
On Vector Functions With A ParameterQUESTJOURNAL
 
Unison Language - Contact
Unison Language - ContactUnison Language - Contact
Unison Language - ContactPhilip Schwarz
 

What's hot (20)

Generics
GenericsGenerics
Generics
 
27418524 design-patterns-dot-net-with-examples
27418524 design-patterns-dot-net-with-examples27418524 design-patterns-dot-net-with-examples
27418524 design-patterns-dot-net-with-examples
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
 
C# Generics
C# GenericsC# Generics
C# Generics
 
Behavioral Design Patterns
Behavioral Design PatternsBehavioral Design Patterns
Behavioral Design Patterns
 
Clean code
Clean codeClean code
Clean code
 
Esoteric LINQ and Structural Madness
Esoteric LINQ and Structural MadnessEsoteric LINQ and Structural Madness
Esoteric LINQ and Structural Madness
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
L09 Frameworks
L09 FrameworksL09 Frameworks
L09 Frameworks
 
Functional Effects - Part 1
Functional Effects - Part 1Functional Effects - Part 1
Functional Effects - Part 1
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
 
Ch5 array nota
Ch5 array notaCh5 array nota
Ch5 array nota
 
Functional Effects - Part 2
Functional Effects - Part 2Functional Effects - Part 2
Functional Effects - Part 2
 
Code smells and remedies
Code smells and remediesCode smells and remedies
Code smells and remedies
 
Assignment 7
Assignment 7Assignment 7
Assignment 7
 
Sofwear deasign and need of design pattern
Sofwear deasign and need of design patternSofwear deasign and need of design pattern
Sofwear deasign and need of design pattern
 
Lesson 6 recursion
Lesson 6  recursionLesson 6  recursion
Lesson 6 recursion
 
On Vector Functions With A Parameter
On Vector Functions With A ParameterOn Vector Functions With A Parameter
On Vector Functions With A Parameter
 
Unison Language - Contact
Unison Language - ContactUnison Language - Contact
Unison Language - Contact
 

Viewers also liked

Viewers also liked (8)

The Language of Interfaces
The Language of InterfacesThe Language of Interfaces
The Language of Interfaces
 
Based Design Pattern Examples
Based Design Pattern ExamplesBased Design Pattern Examples
Based Design Pattern Examples
 
class diagram
class diagramclass diagram
class diagram
 
Class diagrams
Class diagramsClass diagrams
Class diagrams
 
Class diagrams
Class diagramsClass diagrams
Class diagrams
 
Uml class Diagram
Uml class DiagramUml class Diagram
Uml class Diagram
 
Uml class-diagram
Uml class-diagramUml class-diagram
Uml class-diagram
 
Class diagram presentation
Class diagram presentationClass diagram presentation
Class diagram presentation
 

Similar to Design Patterns

Software Frameworks
Software FrameworksSoftware Frameworks
Software Frameworksadil raja
 
Introduction to design_patterns
Introduction to design_patternsIntroduction to design_patterns
Introduction to design_patternsamitarcade
 
Presentation on design pattern software project lll
 Presentation on design pattern  software project lll  Presentation on design pattern  software project lll
Presentation on design pattern software project lll Uchiha Shahin
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 
Object Design - Part 1
Object Design - Part 1Object Design - Part 1
Object Design - Part 1Dhaval Dalal
 
Creational pattern 2
Creational pattern 2Creational pattern 2
Creational pattern 2Naga Muruga
 
1. Mini seminar intro
1. Mini seminar intro1. Mini seminar intro
1. Mini seminar introLeonid Maslov
 
How to design an application correctly ?
How to design an application correctly ?How to design an application correctly ?
How to design an application correctly ?Guillaume AGIS
 
5 Design Patterns Explained
5 Design Patterns Explained5 Design Patterns Explained
5 Design Patterns ExplainedPrabhjit Singh
 
Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2Savio Sebastian
 
Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#Umar Farooq
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patternspradeepkothiyal
 
M04 Design Patterns
M04 Design PatternsM04 Design Patterns
M04 Design PatternsDang Tuan
 
Design patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjsDesign patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjsRavi Bhadauria
 
Software Patterns
Software PatternsSoftware Patterns
Software Patternsbonej010
 

Similar to Design Patterns (20)

Software Frameworks
Software FrameworksSoftware Frameworks
Software Frameworks
 
Introduction to design_patterns
Introduction to design_patternsIntroduction to design_patterns
Introduction to design_patterns
 
Presentation on design pattern software project lll
 Presentation on design pattern  software project lll  Presentation on design pattern  software project lll
Presentation on design pattern software project lll
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Object Design - Part 1
Object Design - Part 1Object Design - Part 1
Object Design - Part 1
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Creational pattern 2
Creational pattern 2Creational pattern 2
Creational pattern 2
 
1. Mini seminar intro
1. Mini seminar intro1. Mini seminar intro
1. Mini seminar intro
 
How to design an application correctly ?
How to design an application correctly ?How to design an application correctly ?
How to design an application correctly ?
 
5 Design Patterns Explained
5 Design Patterns Explained5 Design Patterns Explained
5 Design Patterns Explained
 
Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2
 
Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
 
M04 Design Patterns
M04 Design PatternsM04 Design Patterns
M04 Design Patterns
 
Abstraction
Abstraction Abstraction
Abstraction
 
Abstraction
AbstractionAbstraction
Abstraction
 
Design patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjsDesign patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjs
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 

More from adil raja

A Software Requirements Specification
A Software Requirements SpecificationA Software Requirements Specification
A Software Requirements Specificationadil raja
 
NUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
NUAV - A Testbed for Development of Autonomous Unmanned Aerial VehiclesNUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
NUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehiclesadil raja
 
DevOps Demystified
DevOps DemystifiedDevOps Demystified
DevOps Demystifiedadil raja
 
On Research (And Development)
On Research (And Development)On Research (And Development)
On Research (And Development)adil raja
 
Simulators as Drivers of Cutting Edge Research
Simulators as Drivers of Cutting Edge ResearchSimulators as Drivers of Cutting Edge Research
Simulators as Drivers of Cutting Edge Researchadil raja
 
The Knock Knock Protocol
The Knock Knock ProtocolThe Knock Knock Protocol
The Knock Knock Protocoladil raja
 
File Transfer Through Sockets
File Transfer Through SocketsFile Transfer Through Sockets
File Transfer Through Socketsadil raja
 
Remote Command Execution
Remote Command ExecutionRemote Command Execution
Remote Command Executionadil raja
 
CMM Level 3 Assessment of Xavor Pakistan
CMM Level 3 Assessment of Xavor PakistanCMM Level 3 Assessment of Xavor Pakistan
CMM Level 3 Assessment of Xavor Pakistanadil raja
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousingadil raja
 
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...adil raja
 
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...adil raja
 
Real-Time Non-Intrusive Speech Quality Estimation for VoIP
Real-Time Non-Intrusive Speech Quality Estimation for VoIPReal-Time Non-Intrusive Speech Quality Estimation for VoIP
Real-Time Non-Intrusive Speech Quality Estimation for VoIPadil raja
 
ULMAN GUI Specifications
ULMAN GUI SpecificationsULMAN GUI Specifications
ULMAN GUI Specificationsadil raja
 
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...adil raja
 
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...adil raja
 

More from adil raja (20)

ANNs.pdf
ANNs.pdfANNs.pdf
ANNs.pdf
 
A Software Requirements Specification
A Software Requirements SpecificationA Software Requirements Specification
A Software Requirements Specification
 
NUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
NUAV - A Testbed for Development of Autonomous Unmanned Aerial VehiclesNUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
NUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
 
DevOps Demystified
DevOps DemystifiedDevOps Demystified
DevOps Demystified
 
On Research (And Development)
On Research (And Development)On Research (And Development)
On Research (And Development)
 
Simulators as Drivers of Cutting Edge Research
Simulators as Drivers of Cutting Edge ResearchSimulators as Drivers of Cutting Edge Research
Simulators as Drivers of Cutting Edge Research
 
The Knock Knock Protocol
The Knock Knock ProtocolThe Knock Knock Protocol
The Knock Knock Protocol
 
File Transfer Through Sockets
File Transfer Through SocketsFile Transfer Through Sockets
File Transfer Through Sockets
 
Remote Command Execution
Remote Command ExecutionRemote Command Execution
Remote Command Execution
 
Thesis
ThesisThesis
Thesis
 
CMM Level 3 Assessment of Xavor Pakistan
CMM Level 3 Assessment of Xavor PakistanCMM Level 3 Assessment of Xavor Pakistan
CMM Level 3 Assessment of Xavor Pakistan
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
 
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
 
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
 
Real-Time Non-Intrusive Speech Quality Estimation for VoIP
Real-Time Non-Intrusive Speech Quality Estimation for VoIPReal-Time Non-Intrusive Speech Quality Estimation for VoIP
Real-Time Non-Intrusive Speech Quality Estimation for VoIP
 
VoIP
VoIPVoIP
VoIP
 
ULMAN GUI Specifications
ULMAN GUI SpecificationsULMAN GUI Specifications
ULMAN GUI Specifications
 
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
 
ULMAN-GUI
ULMAN-GUIULMAN-GUI
ULMAN-GUI
 
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
 

Recently uploaded

Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 

Recently uploaded (20)

Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 

Design Patterns

  • 1. Introduction Summary References DESIGN PATTERNS Muhammad Adil Raja Roaming Researchers, Inc. cbna January 29, 2017
  • 2. Introduction Summary References OUTLINE I 1 INTRODUCTION 2 SUMMARY 3 REFERENCES
  • 3. Introduction Summary References INTRODUCTION When faced with a new problem, where do you look for inspiration? Most people look to solutions of previous problems that have similar characteristics. This insight is what is behind design patterns; collections of proven ways to structure the relationships between objects in the pursuit of a given objective.
  • 4. Introduction Summary References INSPIRATION Design patterns speed the process of finding a solution, by eliminating the need to reinvent well-known and proven solutions. Just as important, design patterns provide a vocabulary with which to discuss the space of possible design choices. This vocabulary is termed a pattern language.
  • 5. Introduction Summary References TYPES OF DESIGN PATTERNS Creational: Patterns provide instantiation mechanisms, making it easier to create objects in a way that suits the situation. Structural: Patterns generally deal with relationships between entities, making it easier for these entities to work together. Behavioral: Patterns are used in communications between entities and make it easier and more flexible for these entities to communicate.
  • 6. Introduction Summary References BENEFITS OF USING DESIGN PATTERNS Analogy from civil engineering. Question: What will a civil engineer do when confronted with a problem to cross a river? Answer: Build a tunnel or a bridge. Question: How about preventing rain from entering a window? Answer: Build a canopy. They give the developer a selection of tried and tested solutions to work with. They are language neutral and so can be applied to any language that supports object-orientation. They aid communication by the very fact that they are well documented and can be researched if that is not the case. They have a proven track record as they are already widely used and thus reduce the technical risk to the project. They are highly flexible and can be used in practically any
  • 7. Introduction Summary References RELATIONSHIP TO DEPENDENCY AND VISIBILITY Many patterns are involved with the concepts of dependency we introduced in the previous chapter. Determining where strong dependencies are necessary, and how to weaken dependencies whenever possible.
  • 8. Introduction Summary References A SIMPLE EXAMPLE, THE ADAPTER An adaptor is used to connect a client (an object that needs a service) with a server (an object that provides the service). The client requires a certain interface, and while the server provides the necessary functionality, it does not support the interface. The adapter changes the interface, without actually doing the work.
  • 9. Introduction Summary References AN EXAMPLE ADAPTER EXAMPLE class MyCollection implements Collection { public boolean isEmpty ( ) { return data . count ( ) == 0; } public int size ( ) { return data . count ( ) ; } public void addElement ( Object newElement ) { data . add ( newElement ) ; } public boolean containsElement ( Object t e s t ) { return data . f i n d ( t e s t ) != n u l l ; } public Object findElement ( Object t e s t ) { return data . f i n d ( t e s t ) ; } private DataBox data = new DataBox ( ) ; } Example DataBox is some collection that does not support the Collection interface. Adapters are often needed to connect software from
  • 10. Introduction Summary References DESCRIBING PATTERNS Patterns themselves have developed their own vocabulary for description: NAME: Contributes to the pattern vocabulary. SYNOPSIS: Short description of the problem the pattern will solve. FORCES: Requirements, considerations, or necessary conditions SOLUTION: The essense of the solution COUNTERFORCES: Reasons for not using the pattern. RELATED PATTERNS: Possible alternatives in the design.
  • 11. Introduction Summary References EXAMPLE PATTERNS We will briefly examine a number of common patterns: Iterator. Software Factory. Strategy. Singleton. Composite. Decorator. Double-Dispatch. Flyweight. Proxy. Facade. Observer.
  • 12. Introduction Summary References ITERATOR Problem: How do you provide a client access to elements in a collection, without exposing the structure of the collection. Solution: Allow clients to manipulate an object that can return the current value and move to the next element in the collection. Example, Enumerators in Java. EXAMPLE interface Enumerator { public boolean hasMoreElements ( ) ; public Object nextElement ( ) ; } Enumeator e = . . . ; while ( e . hasMoreElements ) { Object val = e . nextElement ( ) ; . . . }
  • 13. Introduction Summary References SOFTWARE FACTORY INTRODUCTION Problem: How do you simplify the manipulation of many different implementations of the same interface (i.e., iterators). Solution: Hide creation within a method, have the method declare a return type that is more general than its actual return type. EXAMPLE class SortedList { . . . Enumerator elements ( ) { return new SortedListEnumerator ( ) ; } . . . private class SortedListEnumerator implements Enumerator { . . . } }
  • 14. Introduction Summary References SOFTWARE FACTORY The method is the “factory” in the name. Users don’t need to know the exact type the factory returns, only the declared type. The factory could even return different types, depending upon circumstances.
  • 15. Introduction Summary References SOFTWARE FACTORY ANOTHER EXAMPLE FIGURE: Factory
  • 16. Introduction Summary References SOFTWARE FACTORY STEP 1: CREATE AN INTERFACE. SHAPE public interface Shape { void draw ( ) ; }
  • 17. Introduction Summary References SOFTWARE FACTORY STEP 2: CREATE CONCRETE CLASSES IMPLEMENTING THE SAME INTERFACE. RECTANGLE public class Rectangle implements Shape { @Override public void draw ( ) { System . out . p r i n t l n ( " Inside Rectangle : : draw ( ) method . " ) ; } } SQUARE public class Square implements Shape { @Override public void draw ( ) { System . out . p r i n t l n ( " Inside Square : : draw ( ) method . " ) ; } }
  • 18. Introduction Summary References SOFTWARE FACTORY CIRCLE public class Circle implements Shape { @Override public void draw ( ) { System . out . p r i n t l n ( " Inside Circle : : draw ( ) method . " ) ; } }
  • 19. Introduction Summary References SOFTWARE FACTORY STEP 3: CREATE A FACTORY TO GENERATE OBJECT OF CONCRETE CLASS BASED ON GIVEN INFORMATION. SHAPEFACTORY public class ShapeFactory { / / use getShape method to get object of type shape public Shape getShape ( String shapeType ) { i f ( shapeType == null ) { return null ; } i f ( shapeType . equalsIgnoreCase ( "CIRCLE" ) ) { return new Circle ( ) ; } else i f ( shapeType . equalsIgnoreCase ( "RECTANGLE" ) ) { return new Rectangle ( ) ; } else i f ( shapeType . equalsIgnoreCase ( "SQUARE" ) ) { return new Square ( ) ; } return null ; } }
  • 20. Introduction Summary References SOFTWARE FACTORY STEP 4: USE THE FACTORY TO GET OBJECT OF CONCRETE CLASS BY PASSING AN INFORMATION SUCH AS TYPE. FACTORY PATTERN DEMO public class FactoryPatternDemo { public static void main ( String [ ] args ) { ShapeFactory shapeFactory = new ShapeFactory ( ) ; / / get an object of Circle and c a l l i t s draw method . Shape shape1 = shapeFactory . getShape ( "CIRCLE" ) ; / / c a l l draw method of Circle shape1 . draw ( ) ; / / get an object of Rectangle and c a l l i t s draw method . Shape shape2 = shapeFactory . getShape ( "RECTANGLE" ) ; / / c a l l draw method of Rectangle shape2 . draw ( ) ; / / get an object of Square and c a l l i t s draw method . Shape shape3 = shapeFactory . getShape ( "SQUARE" ) ; / / c a l l draw method of c i r c l e shape3 . draw ( ) ; } }
  • 21. Introduction Summary References SOFTWARE FACTORY STEP 5: VERIFY THE OUTPUT. FACTORY PATTERN DEMO Inside Circle::draw() method. Inside Rectangle::draw() method. Inside Square::draw() method.
  • 22. Introduction Summary References STRATEGY Problem: Allow the client the choice of many alternatives, but each is complex, and you don’t want to include code for all. Solution: Make many implementations of the same interface, and allow the client to select one and give it back to you. Example: The layout managers in the AWT. Several different layout managers are implemented, and the designer selects and creates one. Gives the designer flexibility, keeps the code size down.
  • 24. Introduction Summary References STRATEGY STEP 1: CREATE AN INTERFACE. STRATEGY public interface Strategy { public int doOperation ( int num1, int num2 ) ; }
  • 25. Introduction Summary References STRATEGY STEP 2: CREATE CONCRETE CLASSES IMPLEMENTING THE SAME INTERFACE. OPERATION ADD public class OperationAdd implements Strategy { @Override public int doOperation ( int num1, int num2) { return num1 + num2; } } OPERATION SUBTRACT public class OperationSubstract implements Strategy { @Override public int doOperation ( int num1, int num2) { return num1 − num2; } }
  • 26. Introduction Summary References STRATEGY OPERATION MULTIPLY public class OperationMultiply implements Strategy { @Override public int doOperation ( int num1, int num2) { return num1 ∗ num2; } }
  • 27. Introduction Summary References STRATEGY STEP 3: CREATE CONTEXT CLASS. CONTEXT public class Context { private Strategy strategy ; public Context ( Strategy strategy ) { this . strategy = strategy ; } public int executeStrategy ( int num1, int num2 ) { return strategy . doOperation (num1, num2 ) ; } }
  • 28. Introduction Summary References STRATEGY STEP 4: USE THE CONTEXT TO SEE CHANGE IN BEHAVIOUR WHEN IT CHANGES ITS STRATEGY. STRATEGY PATTERN DEMO public class StrategyPatternDemo { public static void main ( String [ ] args ) { Context context = new Context (new OperationAdd ( ) ) ; System . out . p r i n t l n ( " 10 + 5 = " + context . executeStrategy (10 , 5 ) ) ; context = new Context (new OperationSubstract ( ) ) ; System . out . p r i n t l n ( " 10 − 5 = " + context . executeStrategy (10 , 5 ) ) ; context = new Context (new OperationMultiply ( ) ) ; System . out . p r i n t l n ( " 10 ∗ 5 = " + context . executeStrategy (10 , 5 ) ) ; } }
  • 29. Introduction Summary References STRATEGY STEP 5: VERIFY THE OUTPUT. FACTORY PATTERN DEMO 10 + 5 = 15 10 - 5 = 5 10 * 5 = 50
  • 30. Introduction Summary References SINGLETON Problem: You want to ensure that there is never more than one instace of a given class. Solution: Make the constructor private, have a method that returns just one instance, which is held inside the class itself. EXAMPLE class SingletonClass { public : static SingletonClass ∗ oneAndOnly ( ) { return theOne ; } private : static SingletonClass ∗ theOne ; SingletonClass ( ) { . . . } } ; / / s t a t i c i n i t i a l i z a t i o n SingletonClass ∗ SingletonClass : : theOne = new SingletonClass ( ) ;
  • 31. Introduction Summary References COMPOSITE Problem: How do you facilitate creation of complex systems from simple parts? Solution: Provide a few simple components, and a system to compose components (simple or otherwise) into new components. Regular expressions are an example, are type systems, or the nesting of panels within panels in the Java AWT API.
  • 32. Introduction Summary References COMPOSITE AN EXAMPLE FIGURE: Composite
  • 33. Introduction Summary References COMPOSITE STEP 1: CREATE EMPLOYEE CLASS HAVING LIST OF EMPLOYEE OBJECTS. EMPLOYEE import java . u t i l . ArrayList ; import java . u t i l . L i s t ; public class Employee { private String name; private String dept ; private int salary ; private List <Employee> subordinates ; / / constructor public Employee ( String name, String dept , int sal ) { this .name = name; this . dept = dept ; this . salary = sal ; subordinates = new ArrayList <Employee > ( ) ; } public void add ( Employee e ) { subordinates . add ( e ) ; } public void remove ( Employee e ) { subordinates . remove ( e ) ; } public List <Employee> getSubordinates ( ) {
  • 34. Introduction Summary References COMPOSITE STEP 2: USE THE EMPLOYEE CLASS TO CREATE AND PRINT EMPLOYEE HIERARCHY. COMPOSITE PATTERN DEMO public class CompositePatternDemo { public static void main ( String [ ] args ) { Employee CEO = new Employee ( " John " , "CEO" , 30000); Employee headSales = new Employee ( " Robert " , "Head Sales " , 20000); Employee headMarketing = new Employee ( " Michel " , "Head Marketing " , 20000); Employee clerk1 = new Employee ( " Laura " , " Marketing " , 10000); Employee clerk2 = new Employee ( "Bob" , " Marketing " , 10000); Employee salesExecutive1 = new Employee ( " Richard " , " Sales " , 10000); Employee salesExecutive2 = new Employee ( "Rob" , " Sales " , 10000); CEO. add ( headSales ) ; CEO. add ( headMarketing ) ; headSales . add ( salesExecutive1 ) ; headSales . add ( salesExecutive2 ) ; headMarketing . add ( clerk1 ) ; headMarketing . add ( clerk2 ) ; / / p r i n t a l l employees of the organization System . out . p r i n t l n (CEO) ;
  • 35. Introduction Summary References DECORATOR I Filter, wrapper. Problem: Allow functionally to be layered around an abstraction, but still dynamically changeable. Solution: Combine inheritance and composition. By making an object that both subclasses from another class and holds an instance of the class, can add new behaviour while referring all other behaviour to the original class. Example Input Streams in the Java I/O System.
  • 36. Introduction Summary References DECORATOR II EXAMPLE / / a buffered input stream is−an input stream class BufferedInputStream extends InputStream { public BufferedInputStream ( InputStream s ) { data = s ; } . . . / / and a buffered input stream has−an input stream private InputStream data ; } An instance of BufferedInputStream can wrap around any other type of InputStream, and simply adds a little bit new functionality.
  • 37. Introduction Summary References DOUBLE DISPATCH (MULTIPLE POLYMORPHISM) I Problem: You have variation in two or more polymorphic variables. Solution: Make each a receiver in turn, each message ties down one source of variation. Example, suppose we have a hierarchy of Shapes (Triangle, Square) and Device (Printer, Terminal). Two variables, one a Shape and one a Device. First, pass a message to the device, passing the shape as argument:
  • 38. Introduction Summary References DOUBLE DISPATCH (MULTIPLE POLYMORPHISM) II EXAMPLE Shape aShape = . . . ; Device aDevice = . . . ; aDevice . display ( aShape ) ; function P r i n t e r . display ( Shape aShape ) begin aShape . displayOnPrinter ( s e l f ) ; end ; function Terminal . display ( Shape aShape ) begin aShape . displayOnTerminal ( s e l f ) ; end ; One message fixes the device, but how to fix the shape? Each subclass of Shape must implement methods for each output device:
  • 39. Introduction Summary References DOUBLE DISPATCH (MULTIPLE POLYMORPHISM) III EXAMPLE class Triangle : public Shape { public : Triangle ( Point , Point , Point ) ; / / . . . v i r t u a l void displayOnPrinter ( P r i n t e r ) ; v i r t u a l void displayOnTerminal ( Terminal ) ; / / . . . private : Point p1 , p2 , p3 ; } ; void Triangle . displayOnPrinter ( P r i n t e r p ) { / / p r i n t e r−s p e c i f i c code to / / display t r i a n g l e / / . . . } void Triangle . displayOnTerminal ( Terminal t ) { / / terminal−s p e c i f i c code to / / display t r i a n g l e / / . . . }
  • 40. Introduction Summary References PROXY Problem: How to hide unimportant communication details, such as a network, from the client. Solution: A proxy uses the interface that the client expects, but passes messages over the network to the server, gets back the response, and passes it to the client. The client is therefore hidden from the network details. FIGURE: Proxy Similar in some ways to adaptor, but here the intermediary and the server can have the same interface.
  • 42. Introduction Summary References PROXY STEP 1: CREATE AN INTERFACE. IMAGE public interface Image { void display ( ) ; }
  • 43. Introduction Summary References PROXY STEP 2: CREATE CONCRETE CLASSES IMPLEMENTING THE SAME INTERFACE. REAL IMAGE public class RealImage implements Image { private String fileName ; public RealImage ( String fileName ) { this . fileName = fileName ; loadFromDisk ( fileName ) ; } @Override public void display ( ) { System . out . p r i n t l n ( " Displaying " + fileName ) ; } private void loadFromDisk ( String fileName ) { System . out . p r i n t l n ( " Loading " + fileName ) ; } }
  • 44. Introduction Summary References PROXY PROXY IMAGE public class ProxyImage implements Image { private RealImage realImage ; private String fileName ; public ProxyImage ( String fileName ) { this . fileName = fileName ; } @Override public void display ( ) { i f ( realImage == null ) { realImage = new RealImage ( fileName ) ; } realImage . display ( ) ; } }
  • 45. Introduction Summary References PROXY STEP 3: USE THE PROXYIMAGE TO GET OBJECT OF REALIMAGE CLASS WHEN REQUIRED. PROXY PATTERN DEMO public class ProxyPatternDemo { public static void main ( String [ ] args ) { Image image = new ProxyImage ( " test_10mb . jpg " ) ; / / image w i l l be loaded from disk image . display ( ) ; System . out . p r i n t l n ( " " ) ; / / image w i l l not be loaded from disk image . display ( ) ; } }
  • 46. Introduction Summary References PROXY STEP 4: VERIFY THE OUTPUT. FACTORY PATTERN DEMO Loading test_10mb.jpg Displaying test_10mb.jpg Displaying test_10mb.jpg
  • 47. Introduction Summary References FACADE Problem: Actual work is performed by two or more objects, but you want to hide this level of complexity from the client. Solution: Create a facade object that receives the messages, but passes commands on to the workers for completion. FIGURE: Facade Also similar to adapter and proxy.
  • 49. Introduction Summary References FACADE STEP 1: CREATE AN INTERFACE. SHAPE public interface Shape { void draw ( ) ; }
  • 50. Introduction Summary References FACADE STEP 2: CREATE CONCRETE CLASSES IMPLEMENTING THE SAME INTERFACE. RECTANGLE public class Rectangle implements Shape { @Override public void draw ( ) { System . out . p r i n t l n ( " Inside Rectangle : : draw ( ) method . " ) ; } } SQUARE public class Square implements Shape { @Override public void draw ( ) { System . out . p r i n t l n ( " Inside Square : : draw ( ) method . " ) ; } }
  • 51. Introduction Summary References FACADE CIRCLE public class Circle implements Shape { @Override public void draw ( ) { System . out . p r i n t l n ( " Inside Circle : : draw ( ) method . " ) ; } }
  • 52. Introduction Summary References FACADE STEP 3: CREATE A FACADE CLASS. SHAPE MAKER public class ShapeMaker { private Shape c i r c l e ; private Shape rectangle ; private Shape square ; public ShapeMaker ( ) { c i r c l e = new Circle ( ) ; rectangle = new Rectangle ( ) ; square = new Square ( ) ; } public void drawCircle ( ) { c i r c l e . draw ( ) ; } public void drawRectangle ( ) { rectangle . draw ( ) ; } public void drawSquare ( ) { square . draw ( ) ; } }
  • 53. Introduction Summary References FACADE STEP 4: USE THE FACADE TO DRAW VARIOUS TYPES OF SHAPES. FACADE PATTERN DEMO public class FacadePatternDemo { public static void main ( String [ ] args ) { ShapeMaker shapeMaker = new ShapeMaker ( ) ; shapeMaker . drawCircle ( ) ; shapeMaker . drawRectangle ( ) ; shapeMaker . drawSquare ( ) ; } }
  • 54. Introduction Summary References FACADE STEP 5: VERIFY THE OUTPUT. FACADE PATTERN OUTPUT Inside Circle::draw() method. Inside Rectangle::draw() method. Inside Square::draw() method.
  • 55. Introduction Summary References OBSERVER Problem: How do you dynamically (at run time) add and remove connections between objects. Solution: An Observer Manager implements the following protocol: “I Want to Observe X” – the OM will keep track of who is watching who. “Tell Everybody who is Observing Met that I have Changed” – the OM can then tell everybody that an object has changed. In this way neither the observer nor the observed object need know the existance of the other.
  • 56. Introduction Summary References PATTERNS AND FRAMEWORKS Both are ways of describing and documenting solutions to common problems. Frameworks are more “shrinkwrapped”, ready for immediate use. Patterns are more abstract – many patterns are involved in the solution of one problem.
  • 57. Introduction Summary References SUMMARY In this chapter we have examined a variety of topics related to dependency. How classes and objects can depend upon each other. How methods within a class can depend upon each other. How to control visibility, as a means of controlling dependency. How strong dependency can be weakened by using alternative designs.
  • 58. Introduction Summary References REFERENCES Images and content for developing these slides have been taken from the follwoing book with the permission of the author. An Introduction to Object Oriented Programming, Timothy A. Budd. Some examples and text has been used from Tutsplus. Some examples have been taken from Tutorialspoint. Code Project. This presentation is developed with Beamer: Darmstadt, crane.