SlideShare a Scribd company logo
Design Patterns
Proxy & Composite
@sarat, architect
Experion Technologies
composite pattern
is a structural pattern
Structural design patterns ease the
design by identifying a simple way
to realize relationships between
entities
Compose objects into tree structures to represent
part-whole hierarchies.
!
describes that a group of objects are to be treated
in the same way as a single instance of an object
Leaf (primitive element)
• represents leaf objects in the composition.
• A leaf has no children.
• defines behavior for primitive objects in the
composition
Composite
• defines behavior for components having children.
• stores child components.
• implements child-related operations in the
Component interface.
Client
!
• manipulates objects in the composition through the
Component interface.
Design patterns - Proxy & Composite
/** "Component" */	
interface Graphic {	
	
//Prints the graphic.	
public void print();	
}
class CompositeGraphic implements Graphic {	
	
//Collection of child graphics.	
private List<Graphic> childGraphics = new ArrayList<Graphic>();
class CompositeGraphic implements Graphic {	
	
//Collection of child graphics.	
private List<Graphic> childGraphics = new ArrayList<Graphic>();	
!
//Prints the graphic.	
public void print() {	
for (Graphic graphic : childGraphics) {	
graphic.print();	
}	
}
class CompositeGraphic implements Graphic {	
	
//Collection of child graphics.	
private List<Graphic> childGraphics = new ArrayList<Graphic>();	
!
//Prints the graphic.	
public void print() {	
for (Graphic graphic : childGraphics) {	
graphic.print();	
}	
} 	
!
//Adds the graphic to the composition.	
public void add(Graphic graphic) {	
childGraphics.add(graphic);	
}	
	
//Removes the graphic from the composition.	
public void remove(Graphic graphic) {	
childGraphics.remove(graphic);	
}	
}
/** "Leaf" */	
class Ellipse implements Graphic {	
	
//Prints the graphic.	
public void print() {	
System.out.println("Ellipse");	
}	
}
/** Client */	
public class Program {	
	
public static void main(String[] args) {	
//Initialize four ellipses	
Ellipse ellipse1 = new Ellipse();	
Ellipse ellipse2 = new Ellipse();	
Ellipse ellipse3 = new Ellipse();	
Ellipse ellipse4 = new Ellipse();
/** Client */	
public class Program {	
	
public static void main(String[] args) {	
//Initialize four ellipses	
Ellipse ellipse1 = new Ellipse();	
Ellipse ellipse2 = new Ellipse();	
Ellipse ellipse3 = new Ellipse();	
Ellipse ellipse4 = new Ellipse();	
!
//Initialize three composite graphics	
CompositeGraphic graphic = new CompositeGraphic();	
CompositeGraphic graphic1 = new CompositeGraphic();	
CompositeGraphic graphic2 = new CompositeGraphic();
/** Client */	
public class Program {	
	
public static void main(String[] args) {	
//Initialize four ellipses	
Ellipse ellipse1 = new Ellipse();	
Ellipse ellipse2 = new Ellipse();	
Ellipse ellipse3 = new Ellipse();	
Ellipse ellipse4 = new Ellipse();	
!
//Initialize three composite graphics	
CompositeGraphic graphic = new CompositeGraphic();	
CompositeGraphic graphic1 = new CompositeGraphic();	
CompositeGraphic graphic2 = new CompositeGraphic();	
!
//Composes the graphics	
graphic1.add(ellipse1);	
graphic1.add(ellipse2);	
graphic1.add(ellipse3);	
	
graphic2.add(ellipse4);
/** Client */	
public class Program {	
	
public static void main(String[] args) {	
//Initialize four ellipses	
	 	 	 …	
!
//Initialize three composite graphics	
	 	 	 …	
!
//Composes the graphics	
graphic1.add(ellipse1);	
graphic1.add(ellipse2);	
graphic1.add(ellipse3);	
	
graphic2.add(ellipse4);	
graphic.add(graphic1);	
graphic.add(graphic2);	
!
graphic.add(graphic1);	
graphic.add(graphic2);
/** Client */	
public class Program {	
	
public static void main(String[] args) {	
//Initialize four ellipses	
	 	 	 …	
!
//Initialize three composite graphics	
	 	 	 …	
!
//Composes the graphics	
	 	 	 …	
	
	 	 	 …	
!
	 	 	 …	
!
//Prints the complete graphic (4 times "Ellipse").	
graphic.print();	
}
Questions?
What’s proxy pattern?
it makes the clients of a component
communicate with a representative
rather than to the component Itself.
enables enhanced efficiency,
easier access and protection
from unauthorized access.
examples?
a network proxy
large object in memory
reference counting
pointer objects
Context
• A client needs access to the services of
another component
• Direct access is technically possible, but
may not be the best approach
Problem
• Often it’s inappropriate to access the
component directly
• Direct and unrestricted access can be
insecure and inefficient
Key considerations
run-time efficient
cost effective
safe for both client and
component
transparent interfaces
should be similar to
component’s interface
aware of performance
penalties
solution
communicate to
representative — proxy
proxy performs
pre & post processing (e.g
access control)
structure
uses proxy to fulfill it’s
task
Client
a common interface for
proxy and original
AbstractOriginal
provides interface of the
original to clients
proxy
ensures safe, efficient and
correct access to the
original
proxy
collaborates with
original
proxy
implements a particular
service
Original
Design patterns - Proxy & Composite
dynamics
Design patterns - Proxy & Composite
implementation
considerations
migrate all client
responsibilities to proxy
remove all direct
relationship with client
and original
variants
To shield network addresses and inter-process communication
protocols from clients
Remote Proxy
Access authorization 

e.g network authorization to use Internet
Protection Proxy
Multiple local components can share results from a remote proxy

e.g. Cache server
Cache Proxy
Provide synchronized access to services in a multi-access or multi-
threaded environment
Synchronization Proxy
Prevents accidental deletion of components or collects usage
statistics

e.g. reference counting objects
Counting Proxy
Protects local clients from outside world
Firewall proxy
benefits
enhanced efficiency and
lower cost
e.g. cache proxy
decouple clients from
real objects
separate housekeeping
from functionality
liabilities
less efficiency due to
indirection
overkill using sophisticated strategies
!
e.g. caching server in a dynamic
environment
Questions?

More Related Content

PPTX
Design Patterns - 03 Composite and Flyweight Pattern
PPT
Composite Design Pattern
PPTX
Proxy Design Pattern
PPT
Design pattern composite 20120413 joncash 01
PPT
Flyweight pattern
PPT
Composite Pattern
PPTX
Proxy Design Patterns
PPTX
Proxy Pattern
Design Patterns - 03 Composite and Flyweight Pattern
Composite Design Pattern
Proxy Design Pattern
Design pattern composite 20120413 joncash 01
Flyweight pattern
Composite Pattern
Proxy Design Patterns
Proxy Pattern

What's hot (20)

PPSX
Proxy design pattern
PDF
Proxy design pattern (Class Ambassador)
PPTX
Creational pattern
PPT
Proxy pattern
PPTX
PATTERNS04 - Structural Design Patterns
PPTX
Composite design pattern
PPT
Proxy pattern
PPTX
PDF
Software Design Patterns. Part I :: Structural Patterns
PDF
Design patterns
PPT
Design patterns
PPTX
Oops in vb
PPSX
Concept of Object Oriented Programming
PPTX
PATTERNS03 - Behavioural Design Patterns
PDF
Design Patterns
PDF
Java design patterns
PPTX
Encapsulation of operations, methods & persistence
ODP
Mediator
ODP
Visitor pattern
PPTX
Design patterns
Proxy design pattern
Proxy design pattern (Class Ambassador)
Creational pattern
Proxy pattern
PATTERNS04 - Structural Design Patterns
Composite design pattern
Proxy pattern
Software Design Patterns. Part I :: Structural Patterns
Design patterns
Design patterns
Oops in vb
Concept of Object Oriented Programming
PATTERNS03 - Behavioural Design Patterns
Design Patterns
Java design patterns
Encapsulation of operations, methods & persistence
Mediator
Visitor pattern
Design patterns
Ad

Viewers also liked (11)

PPT
RAVELLO LAB 2014 | E-Production
PPTX
Managing CATIA V5 in PDM... Simply for COE Ask The Expert
PPT
Composite automobile leaf spring-Fatigue life
PPTX
Running OpenStack on Amazon AWS, Alex Fishman
PDF
Getting started with CATIA V5 Macros
PPTX
ANSYS Brake Simulation
PDF
Catia v5 NOTES
PPT
Z:\catia v5
PDF
CATIA V5 Tips and Tricks
PPTX
LEAF SPRING
PDF
LinkedIn SlideShare: Knowledge, Well-Presented
RAVELLO LAB 2014 | E-Production
Managing CATIA V5 in PDM... Simply for COE Ask The Expert
Composite automobile leaf spring-Fatigue life
Running OpenStack on Amazon AWS, Alex Fishman
Getting started with CATIA V5 Macros
ANSYS Brake Simulation
Catia v5 NOTES
Z:\catia v5
CATIA V5 Tips and Tricks
LEAF SPRING
LinkedIn SlideShare: Knowledge, Well-Presented
Ad

Similar to Design patterns - Proxy & Composite (20)

PPTX
Composite pattern.pptx
PPT
M04 Design Patterns
PPT
Composite pattern
PPTX
PPTX
Composite presentation for engineering.pptx
PPTX
Design pattern and their application
PDF
Module 4: UML In Action - Design Patterns
PPT
M04_DesignPatterns software engineering.ppt
PDF
Design Patterns
PDF
Bab 11 component diagram 2010
PDF
Modeling Aspects with AP&P Components
PPTX
Architecture and design
PDF
ECOOP01 PhDOOS.ppt
PPT
Component Diagram
PPTX
Esoteric LINQ and Structural Madness
PPTX
unified modelling language(UML) diagrams
PPTX
Design pattern proxy介紹 20130805
PPTX
Design pattern proxy介紹 20130805
PPTX
GoF Design patterns I: Introduction + Structural Patterns
Composite pattern.pptx
M04 Design Patterns
Composite pattern
Composite presentation for engineering.pptx
Design pattern and their application
Module 4: UML In Action - Design Patterns
M04_DesignPatterns software engineering.ppt
Design Patterns
Bab 11 component diagram 2010
Modeling Aspects with AP&P Components
Architecture and design
ECOOP01 PhDOOS.ppt
Component Diagram
Esoteric LINQ and Structural Madness
unified modelling language(UML) diagrams
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
GoF Design patterns I: Introduction + Structural Patterns

Recently uploaded (20)

PPTX
Special finishes, classification and types, explanation
PDF
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
PDF
Quality Control Management for RMG, Level- 4, Certificate
PDF
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
PPTX
ANATOMY OF ANTERIOR CHAMBER ANGLE AND GONIOSCOPY.pptx
PPT
Machine printing techniques and plangi dyeing
PPTX
EDP Competencies-types, process, explanation
PPTX
Entrepreneur intro, origin, process, method
PPTX
Causes of Flooding by Slidesgo sdnl;asnjdl;asj.pptx
PPTX
An introduction to AI in research and reference management
PDF
BRANDBOOK-Presidential Award Scheme-Kenya-2023
PDF
Urban Design Final Project-Site Analysis
PDF
Urban Design Final Project-Context
PDF
YOW2022-BNE-MinimalViableArchitecture.pdf
PPTX
Media And Information Literacy for Grade 12
PPT
pump pump is a mechanism that is used to transfer a liquid from one place to ...
PDF
Chalkpiece Annual Report from 2019 To 2025
PPTX
AD Bungalow Case studies Sem 2.pptxvwewev
PDF
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
PDF
SEVA- Fashion designing-Presentation.pdf
Special finishes, classification and types, explanation
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
Quality Control Management for RMG, Level- 4, Certificate
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
ANATOMY OF ANTERIOR CHAMBER ANGLE AND GONIOSCOPY.pptx
Machine printing techniques and plangi dyeing
EDP Competencies-types, process, explanation
Entrepreneur intro, origin, process, method
Causes of Flooding by Slidesgo sdnl;asnjdl;asj.pptx
An introduction to AI in research and reference management
BRANDBOOK-Presidential Award Scheme-Kenya-2023
Urban Design Final Project-Site Analysis
Urban Design Final Project-Context
YOW2022-BNE-MinimalViableArchitecture.pdf
Media And Information Literacy for Grade 12
pump pump is a mechanism that is used to transfer a liquid from one place to ...
Chalkpiece Annual Report from 2019 To 2025
AD Bungalow Case studies Sem 2.pptxvwewev
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
SEVA- Fashion designing-Presentation.pdf

Design patterns - Proxy & Composite