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

What's hot (20)

PPSX
Proxy design pattern
Sase Kleckovski
 
PDF
Proxy design pattern (Class Ambassador)
Sameer Rathoud
 
PPTX
Creational pattern
Himanshu
 
PPT
Proxy pattern
Chester Hartin
 
PPTX
PATTERNS04 - Structural Design Patterns
Michael Heron
 
PPTX
Composite design pattern
MUHAMMAD FARHAN ASLAM
 
PPT
Proxy pattern
Shakil Ahmed
 
PPTX
Sda 8
AmberMughal5
 
PDF
Software Design Patterns. Part I :: Structural Patterns
Sergey Aganezov
 
PDF
Design patterns
Anas Alpure
 
PPT
Design patterns
mudabbirwarsi
 
PPTX
Oops in vb
Dalwin INDIA
 
PPSX
Concept of Object Oriented Programming
Prognoz Technologies Pvt. Ltd.
 
PPTX
PATTERNS03 - Behavioural Design Patterns
Michael Heron
 
PDF
Design Patterns
Ahmad Hussein
 
PDF
Java design patterns
Shawn Brito
 
PPTX
Encapsulation of operations, methods & persistence
Prem Lamsal
 
ODP
Mediator
Iryney Baran
 
ODP
Visitor pattern
Nikunj Dhameliya
 
PPTX
Design patterns
F(x) Data Labs Pvt Ltd
 
Proxy design pattern
Sase Kleckovski
 
Proxy design pattern (Class Ambassador)
Sameer Rathoud
 
Creational pattern
Himanshu
 
Proxy pattern
Chester Hartin
 
PATTERNS04 - Structural Design Patterns
Michael Heron
 
Composite design pattern
MUHAMMAD FARHAN ASLAM
 
Proxy pattern
Shakil Ahmed
 
Software Design Patterns. Part I :: Structural Patterns
Sergey Aganezov
 
Design patterns
Anas Alpure
 
Design patterns
mudabbirwarsi
 
Oops in vb
Dalwin INDIA
 
Concept of Object Oriented Programming
Prognoz Technologies Pvt. Ltd.
 
PATTERNS03 - Behavioural Design Patterns
Michael Heron
 
Design Patterns
Ahmad Hussein
 
Java design patterns
Shawn Brito
 
Encapsulation of operations, methods & persistence
Prem Lamsal
 
Mediator
Iryney Baran
 
Visitor pattern
Nikunj Dhameliya
 
Design patterns
F(x) Data Labs Pvt Ltd
 

Viewers also liked (11)

PPT
RAVELLO LAB 2014 | E-Production
Creactivitas
 
PPTX
Managing CATIA V5 in PDM... Simply for COE Ask The Expert
Razorleaf Corporation
 
PPT
Composite automobile leaf spring-Fatigue life
Padmanabhan Krishnan
 
PPTX
Running OpenStack on Amazon AWS, Alex Fishman
Cloud Native Day Tel Aviv
 
PDF
Getting started with CATIA V5 Macros
Emmett Ross
 
PPTX
ANSYS Brake Simulation
Ansys
 
PDF
Catia v5 NOTES
vipinshelke
 
PPT
Z:\catia v5
Shintu Shukla
 
PDF
CATIA V5 Tips and Tricks
Emmett Ross
 
PPTX
LEAF SPRING
Nani Santosh
 
PDF
LinkedIn SlideShare: Knowledge, Well-Presented
SlideShare
 
RAVELLO LAB 2014 | E-Production
Creactivitas
 
Managing CATIA V5 in PDM... Simply for COE Ask The Expert
Razorleaf Corporation
 
Composite automobile leaf spring-Fatigue life
Padmanabhan Krishnan
 
Running OpenStack on Amazon AWS, Alex Fishman
Cloud Native Day Tel Aviv
 
Getting started with CATIA V5 Macros
Emmett Ross
 
ANSYS Brake Simulation
Ansys
 
Catia v5 NOTES
vipinshelke
 
Z:\catia v5
Shintu Shukla
 
CATIA V5 Tips and Tricks
Emmett Ross
 
LEAF SPRING
Nani Santosh
 
LinkedIn SlideShare: Knowledge, Well-Presented
SlideShare
 
Ad

Similar to Design patterns - Proxy & Composite (20)

PPTX
Composite pattern.pptx
SeetharamNageshAppe1
 
PPT
M04 Design Patterns
Dang Tuan
 
PPT
Composite pattern
Shakil Ahmed
 
PPTX
Sda 9
AmberMughal5
 
PPTX
Composite presentation for engineering.pptx
rythmoflove8
 
PPTX
Design pattern and their application
Hiệp Tiến
 
PDF
Module 4: UML In Action - Design Patterns
jaden65832
 
PPT
M04_DesignPatterns software engineering.ppt
ssuser2d043c
 
PDF
Design Patterns
adil raja
 
PDF
Bab 11 component diagram 2010
donasiilmu
 
PDF
Modeling Aspects with AP&P Components
mukhtarhudaya
 
PPTX
Architecture and design
himanshu_airon
 
PDF
ECOOP01 PhDOOS.ppt
Ptidej Team
 
PPT
Component Diagram
Ahmed Yousef
 
PPTX
Esoteric LINQ and Structural Madness
Chris Eargle
 
PPTX
unified modelling language(UML) diagrams
pratyashi satapathy
 
PPTX
Design pattern proxy介紹 20130805
LearningTech
 
PPTX
Design pattern proxy介紹 20130805
LearningTech
 
PPTX
GoF Design patterns I: Introduction + Structural Patterns
Sameh Deabes
 
Composite pattern.pptx
SeetharamNageshAppe1
 
M04 Design Patterns
Dang Tuan
 
Composite pattern
Shakil Ahmed
 
Composite presentation for engineering.pptx
rythmoflove8
 
Design pattern and their application
Hiệp Tiến
 
Module 4: UML In Action - Design Patterns
jaden65832
 
M04_DesignPatterns software engineering.ppt
ssuser2d043c
 
Design Patterns
adil raja
 
Bab 11 component diagram 2010
donasiilmu
 
Modeling Aspects with AP&P Components
mukhtarhudaya
 
Architecture and design
himanshu_airon
 
ECOOP01 PhDOOS.ppt
Ptidej Team
 
Component Diagram
Ahmed Yousef
 
Esoteric LINQ and Structural Madness
Chris Eargle
 
unified modelling language(UML) diagrams
pratyashi satapathy
 
Design pattern proxy介紹 20130805
LearningTech
 
Design pattern proxy介紹 20130805
LearningTech
 
GoF Design patterns I: Introduction + Structural Patterns
Sameh Deabes
 
Ad

Recently uploaded (20)

PPTX
In the sweet by and by, We shall meet on that beautiful shore; In the sweet b...
kuysniya14
 
PPTX
N-doped FSHC 2nrdddddddddddddddddrrrd.pptx
71762306019
 
DOCX
Non_Communicable_Diseases_Risk_Assessment,_Prevention,_Control,.docx
DrFatemaTuzzannat
 
PDF
CRAC- Adobe Photoshop CC 2016 (32 64Bit) Crack
utfefguu
 
PDF
Presentation of design made by power point
habibikuw002
 
DOCX
Ai vehicle traffic signal detector research proposal.docx
DavidNameza
 
PPTX
(2) Cell Wall Inhibitors_Cephalosporins others.pptx
mkurdi133
 
PDF
Dynamic Visuals for NJ Commercial Spaces
Yantram Animation Studio Corporation
 
PPTX
Light weight Concrete-CONCRETE TECHNOLOGY.
mayurbhandari2123
 
PDF
Florida Gulf Coast University (FGCU) Diploma
bogusdiploma
 
PDF
PHILGOV-QUIZ-_20250625_182551_000.pdfhehe
errollnas3
 
PPTX
6. PMES PORTFOLIO_PINK DESIGN_T1-TE_A4.pptx
GynnelNicanor1
 
DOCX
Ai Vehicle traffic signal detector Literature Review.
DavidNameza
 
PPTX
PowerUpKit_Favorite.pptxcccccccccccccccv
ELiasAtasaUdo
 
PPTX
Face ATM nadar saraswathi college of arts and science, vadaputhupatti- Full....
priyaayalraj
 
PPTX
Cisco SDWAN presentation for Headquarters
dayoo0186
 
PDF
Introductory Plant Pathology Class Slides.pdf
tabishek325
 
PDF
IPC_Reference_manual_Vol_1_Final (1).pdf
AbrahamFekede1
 
PPTX
CHINA CONVENTION CENTRE casestudy and analysis
FullygamesTech
 
PPTX
Types of post tensioning methods (2).pptx
RizwanAlavi
 
In the sweet by and by, We shall meet on that beautiful shore; In the sweet b...
kuysniya14
 
N-doped FSHC 2nrdddddddddddddddddrrrd.pptx
71762306019
 
Non_Communicable_Diseases_Risk_Assessment,_Prevention,_Control,.docx
DrFatemaTuzzannat
 
CRAC- Adobe Photoshop CC 2016 (32 64Bit) Crack
utfefguu
 
Presentation of design made by power point
habibikuw002
 
Ai vehicle traffic signal detector research proposal.docx
DavidNameza
 
(2) Cell Wall Inhibitors_Cephalosporins others.pptx
mkurdi133
 
Dynamic Visuals for NJ Commercial Spaces
Yantram Animation Studio Corporation
 
Light weight Concrete-CONCRETE TECHNOLOGY.
mayurbhandari2123
 
Florida Gulf Coast University (FGCU) Diploma
bogusdiploma
 
PHILGOV-QUIZ-_20250625_182551_000.pdfhehe
errollnas3
 
6. PMES PORTFOLIO_PINK DESIGN_T1-TE_A4.pptx
GynnelNicanor1
 
Ai Vehicle traffic signal detector Literature Review.
DavidNameza
 
PowerUpKit_Favorite.pptxcccccccccccccccv
ELiasAtasaUdo
 
Face ATM nadar saraswathi college of arts and science, vadaputhupatti- Full....
priyaayalraj
 
Cisco SDWAN presentation for Headquarters
dayoo0186
 
Introductory Plant Pathology Class Slides.pdf
tabishek325
 
IPC_Reference_manual_Vol_1_Final (1).pdf
AbrahamFekede1
 
CHINA CONVENTION CENTRE casestudy and analysis
FullygamesTech
 
Types of post tensioning methods (2).pptx
RizwanAlavi
 

Design patterns - Proxy & Composite