SlideShare a Scribd company logo
1 of 25
Structural
Design Patterns
Michael Heron
Introduction
 Structural design patterns emphasize
relationships between entities.
 These can be classes or objects.
 They are designed to help deal with the
combinatorial complexity of large object
oriented programs.
 These often exhibit behaviours that are not
immediately intuitive.
Structural Patterns
 Common to the whole philosophy behind
structural patterns is the separation between
abstraction and implementation.
 This is a good guideline for extensible design.
 Structural patterns subdivide into two broad
subcategories.
 Class structural patterns
 Where the emphasis is on the relationship
between classes
 Object structural patterns
 The emphasis is on consistency of interaction
and realization of new functionality.
Façade
 When a model is especially complex, it can
be useful to add in an additional pattern to
help manage the external interface of that
model.
 That pattern is called a façade.
 A façade sits between the view/controller
and provides a stripped down or simplified
interface to complex functionality.
 There are costs to this though in terms of
coupling and cohesion.
 A façade is a structural pattern.
Façade
 A façade provides several benefits
 Makes software libraries easier to use by
providing helper methods
 Makes code more readable
 Can abstract away from the
implementation details of a complex library
or collection of classes.
 Can work as a wrapper for poorly designed
APIs, or for complex compound
relationships between objects.
Façade Example
public class FacadeExample {
SomeClass one;
SomeOtherClass two;
SomeKindOfConfigClass three;
public SomeOtherClass handleInput (String configInfo) {
three = SomeKindOfConfigClass (configInfo)
one = new SomeClass (configInfo);
two = one.getSomethingOut ();
return two;
}
}
Façade Example
public class FacadeExample {
public SomeOtherClass handleInput (String configInfo) {
return myFacade.doSomeMagic (configInfo);
}
}
public class Facade {
SomeClass one;
SomeOtherClass two;
SomeKindOfConfigClass three;
public SomeOtherClass doSomeMagic (String configInfo) {
three = SomeKindOfConfigClass (configInfo)
one = new SomeClass (configInfo);
two = one.getSomethingOut ();
return two;
}
}
Façade
 The more code that goes through the
façade, the more powerful it becomes.
 If just used in one place, it has limited benefit.
 Multiple objects can make use of the façade.
 Greatly increasing the easy of development
and reducing the impact of change.
 All the user has to know is what needs to go
in, and what comes out.
 The façade hides the rest
Downsides
 This comes with a necessary loss of control.
 You don’t really know what’s happening internally.
 Facades are by definition simplified interfaces.
 So you may not be able to do Clever Stuff when
blocked by one.
 Facades increase structural complexity.
 It’s a class that didn’t exist before.
 Facades increase coupling and reduce cohesion.
 They often have to link everywhere, and the set of
methods they expose often lack consistency
The Adapter
 The Adapter design pattern is used to
provide compatibility between
incompatible programming interfaces.
 This can be used to provide legacy support,
or consistency between different APIs.
 These are also sometimes called
wrappers.
 We have a class that wraps around another
class and presents an external interface.
The Adapter
 Internally, an adapter can be as simple as
a composite object and a method that
handles translations.
 We can combine this with other design
patterns to get more flexible solutions.
 For example, a factory for adapters
 Or adapters that work using the strategy
pattern.
 It is the combination of design patterns
that has the greatest potential in design.
Simple Example
abstract class Shape {
abstract void drawShape (Graphics g, int x1, int x2, int y1, int y2);
}
public class Adapter {
private Shape sh;
public void drawShape (int x, int y, int len, int ht, Graphics g) {
sh.drawShape (g, x, x+ht, y, y+len);
}
}
Adapters and Facades
 What’s the difference between a façade and
an adapter?
 A façade presents a new simplified API to
external objects.
 An adapter converts an existing API to a
common standard.
 The Façade creates the programming
interface for the specific combination of
objects.
 The adapter simply enforces consistency
between incompatible interfaces.
The Flyweight
 Object oriented programming languages
provide fine-grained control over data
and behaviours.
 But that flexibility comes at a cost.
 The Flyweight pattern is used to reduce
the memory and instantiation cost when
dealing with large numbers of finely-
grained objects.
 It does this by sharing state whenever
possible.
Scenario
 Imagine a word processor.
 They’re pretty flexible. You can store decoration
detail on any character in the text.
 How is this done?
 You could represent each character as an object.
 You could have each character contain its own
font object…
 … but that’s quite a memory overhead.
 It would be much better if instead of holding a
large font object, we held only a reference to a
font object.
The Flyweight
 The Flyweight pattern comes in to reduce the
state requirements here.
 It maintains a cache of previously utilised
configurations or styles.
 Each character is given a reference to a
configuration object.
 When a configuration is applied, we check the
cache to see if it exists.
 If it doesn’t, it creates one and add it to the cache.
 The Flyweight dramatically reduces the object
footprint.
 We have thousands of small objects rather than
thousands of large objects.
Before and After
public class MyCharacter {
char letter;
Font myFont;
void applyDecoration (string font, int size);
myFont = new Font (font, size);
}
}
public class MyCharacter {
char letter;
Font myFont;
void applyDecoration (string font, int size);
myFont = FlyweightCache.getFont (font, size);
}
}
Implementing a Flyweight
 The flyweight patterns makes no
implementation assumptions.
 A reasonably good way to do it is through a
hash map or other collection.
 Standard memoization techniques can be
used here.
 When a request is made, check the cache.
 If it’s there, return it.
 If it’s not, create it and put it in the cache and
return the new instance.
Limitations of the Flyweight
Pattern
 Flyweight is only an appropriate design
pattern when object references have no
context.
 As in, it doesn’t matter to what they are being
applied.
 A font object is a good example.
 It doesn’t matter if it’s being applied to a
number, a character, or a special symbol.
 A customer object is a bad example.
 Each customer is unique.
The Composite Pattern
 We often have to manipulate collections of
objects when programming.
 The composite pattern is designed to simplify
this.
 Internally, it represents data as a simple list or
other collection.
 Requires the use of polymorphism to assure
structural compatability.
 Externally it presents an API to add and
remove objects.
 And also to execute operations on the
collection as a whole.
The Composite Pattern
public class ShapeCollection implements Shape() {
ArrayList shapes = new ArrayList();
void addShape (Shape s) {
shapes.Add (s);
}
void removeShape (Shape s) {
shapes.Remove (s);
}
void draw() {
foreach (Shape s in shapes) {
s.draw();
}
}
void setColour (Colour c) {
foreach (Shape s in shapes) {
s.setColour (c);
}
}
}
The Composite Pattern
public MainProgram() {
Circle circle = new Circle();
Rectangle rect = new Rectangle();
Triangle tri = new Triangle();
ShapeCollection myCollection = new ShapeCollection();
ShapeCollection overallScene = new ShapeCollection();
myCollection.addShape (circle);
myCollection.addShape (rect);
overallScene.addShape (myCollection);
overallScene.addShape (tri);
myCollection.setColour (Colour.RED);
overallScene.draw();
}
Why Use Composite?
 Sometimes we need to be able to perform
operations on groups of objects as a whole.
 We may wish to move a group of shapes in a
graphics package as one example.
 These often exist side by side with more
primitive objects that get manipulated
individually.
 Having handling code for each of these
conditions is bad design.
The Composite
 The composite allows us to treat
collections and individual objects through
one consistent interface.
 We don’t need to worry about which we
are dealing with at any one time.
 It works by ensuring that the collection
implements the common interface shared
by all its constituent bits.
 The relationship is recursive if done
correctly.
Summary
 Structural patterns are the last of the families of
design patterns we are going to look at.
 We use an adapter to deal with incompatible
APIs.
 We use a bridge to decouple abstraction from
implementation.
 Implementation is very similar to strategy, only the
intent is unique.
 Flyweight patterns are used to reduce processing
and memory overheads.
 Composites are used to allow recursive and
flexible aggregate manipulation of objects.

More Related Content

What's hot

What's hot (20)

Creational pattern
Creational patternCreational pattern
Creational pattern
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design Pattern
Design PatternDesign Pattern
Design Pattern
 
Prototype Design Pattern
Prototype Design PatternPrototype Design Pattern
Prototype Design Pattern
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Prototype_pattern
Prototype_patternPrototype_pattern
Prototype_pattern
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Design pattern
Design patternDesign pattern
Design pattern
 
What is design pattern
What is design patternWhat is design pattern
What is design pattern
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 
PATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsPATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design Patterns
 

Viewers also liked

Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSergey Aganezov
 
Structural Design pattern - Adapter
Structural Design pattern - AdapterStructural Design pattern - Adapter
Structural Design pattern - AdapterManoj Kumar
 
PATTERNS03 - Behavioural Design Patterns
PATTERNS03 - Behavioural Design PatternsPATTERNS03 - Behavioural Design Patterns
PATTERNS03 - Behavioural Design PatternsMichael Heron
 
Musings on misconduct
Musings on misconductMusings on misconduct
Musings on misconductMichael Heron
 
Singleton Object Management
Singleton Object ManagementSingleton Object Management
Singleton Object Managementppd1961
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonJonathan Simon
 
Singleton class in Java
Singleton class in JavaSingleton class in Java
Singleton class in JavaRahul Sharma
 
Construction Management in Developing Countries, Lecture 8
Construction Management in Developing Countries, Lecture 8Construction Management in Developing Countries, Lecture 8
Construction Management in Developing Countries, Lecture 8Hari Krishna Shrestha
 
Code & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven DesignCode & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven DesignFrank Levering
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Patternguy_davis
 
Domain Driven Design Development Spring Portfolio
Domain Driven Design Development Spring PortfolioDomain Driven Design Development Spring Portfolio
Domain Driven Design Development Spring PortfolioSrini Penchikala
 
003 obf600105 gpon ma5608 t basic operation and maintenance v8r15 issue1.02 (...
003 obf600105 gpon ma5608 t basic operation and maintenance v8r15 issue1.02 (...003 obf600105 gpon ma5608 t basic operation and maintenance v8r15 issue1.02 (...
003 obf600105 gpon ma5608 t basic operation and maintenance v8r15 issue1.02 (...Cavanghetboi Cavangboihet
 
A Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation SlidesA Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation Slidesthinkddd
 
Rem Koolhaas –designing the design process
Rem Koolhaas –designing the design processRem Koolhaas –designing the design process
Rem Koolhaas –designing the design processSjors Timmer
 
Domain Driven Design using Laravel
Domain Driven Design using LaravelDomain Driven Design using Laravel
Domain Driven Design using Laravelwajrcs
 
Bar bending schedule(by akhil)
Bar bending schedule(by akhil)Bar bending schedule(by akhil)
Bar bending schedule(by akhil)Lamdade Akhil
 

Viewers also liked (20)

Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
 
Structural Design pattern - Adapter
Structural Design pattern - AdapterStructural Design pattern - Adapter
Structural Design pattern - Adapter
 
PATTERNS03 - Behavioural Design Patterns
PATTERNS03 - Behavioural Design PatternsPATTERNS03 - Behavioural Design Patterns
PATTERNS03 - Behavioural Design Patterns
 
Musings on misconduct
Musings on misconductMusings on misconduct
Musings on misconduct
 
Singleton Object Management
Singleton Object ManagementSingleton Object Management
Singleton Object Management
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
 
Singleton class in Java
Singleton class in JavaSingleton class in Java
Singleton class in Java
 
Construction Management in Developing Countries, Lecture 8
Construction Management in Developing Countries, Lecture 8Construction Management in Developing Countries, Lecture 8
Construction Management in Developing Countries, Lecture 8
 
Code & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven DesignCode & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven Design
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Domain Driven Design Development Spring Portfolio
Domain Driven Design Development Spring PortfolioDomain Driven Design Development Spring Portfolio
Domain Driven Design Development Spring Portfolio
 
003 obf600105 gpon ma5608 t basic operation and maintenance v8r15 issue1.02 (...
003 obf600105 gpon ma5608 t basic operation and maintenance v8r15 issue1.02 (...003 obf600105 gpon ma5608 t basic operation and maintenance v8r15 issue1.02 (...
003 obf600105 gpon ma5608 t basic operation and maintenance v8r15 issue1.02 (...
 
A Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation SlidesA Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation Slides
 
Structure as Architecture
Structure as ArchitectureStructure as Architecture
Structure as Architecture
 
Rem Koolhaas –designing the design process
Rem Koolhaas –designing the design processRem Koolhaas –designing the design process
Rem Koolhaas –designing the design process
 
Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
 
Types of structures
Types of structuresTypes of structures
Types of structures
 
Domain Driven Design using Laravel
Domain Driven Design using LaravelDomain Driven Design using Laravel
Domain Driven Design using Laravel
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Bar bending schedule(by akhil)
Bar bending schedule(by akhil)Bar bending schedule(by akhil)
Bar bending schedule(by akhil)
 

Similar to Structural Design Patterns Explained: Facade, Adapter, Flyweight & Composite

M04 Design Patterns
M04 Design PatternsM04 Design Patterns
M04 Design PatternsDang Tuan
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3Naga Muruga
 
Software System Architecture-Lecture 6.pptx
Software System Architecture-Lecture 6.pptxSoftware System Architecture-Lecture 6.pptx
Software System Architecture-Lecture 6.pptxssuser9a23691
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design PatternsLilia Sfaxi
 
Design Patterns
Design PatternsDesign Patterns
Design Patternsadil raja
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Luis Valencia
 
Design Patterns By Sisimon Soman
Design Patterns By Sisimon SomanDesign Patterns By Sisimon Soman
Design Patterns By Sisimon SomanSisimon Soman
 
Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2Savio Sebastian
 
Design patterns in brief
Design patterns in briefDesign patterns in brief
Design patterns in briefDUONG Trong Tan
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singhdheeraj_cse
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Pythondn
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patternspradeepkothiyal
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 

Similar to Structural Design Patterns Explained: Facade, Adapter, Flyweight & Composite (20)

M04 Design Patterns
M04 Design PatternsM04 Design Patterns
M04 Design Patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Software System Architecture-Lecture 6.pptx
Software System Architecture-Lecture 6.pptxSoftware System Architecture-Lecture 6.pptx
Software System Architecture-Lecture 6.pptx
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
Design Patterns By Sisimon Soman
Design Patterns By Sisimon SomanDesign Patterns By Sisimon Soman
Design Patterns By Sisimon Soman
 
Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2
 
Composite Design Pattern
Composite Design PatternComposite Design Pattern
Composite Design Pattern
 
Design patterns in brief
Design patterns in briefDesign patterns in brief
Design patterns in brief
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Sda 9
Sda   9Sda   9
Sda 9
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 

More from Michael Heron

Meeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMeeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMichael Heron
 
Accessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkAccessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkMichael Heron
 
ACCESS: A Technical Framework for Adaptive Accessibility Support
ACCESS:  A Technical Framework for Adaptive Accessibility SupportACCESS:  A Technical Framework for Adaptive Accessibility Support
ACCESS: A Technical Framework for Adaptive Accessibility SupportMichael Heron
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and AutershipMichael Heron
 
Text parser based interaction
Text parser based interactionText parser based interaction
Text parser based interactionMichael Heron
 
GRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityGRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityMichael Heron
 
GRPHICS07 - Textures
GRPHICS07 - TexturesGRPHICS07 - Textures
GRPHICS07 - TexturesMichael Heron
 
GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)Michael Heron
 
GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)Michael Heron
 
GRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationGRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationMichael Heron
 
GRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsGRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsMichael Heron
 
GRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsGRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsMichael Heron
 
GRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationGRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationMichael Heron
 
2CPP14 - Abstraction
2CPP14 - Abstraction2CPP14 - Abstraction
2CPP14 - AbstractionMichael Heron
 

More from Michael Heron (20)

Meeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMeeple centred design - Board Game Accessibility
Meeple centred design - Board Game Accessibility
 
Accessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkAccessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS Framework
 
ACCESS: A Technical Framework for Adaptive Accessibility Support
ACCESS:  A Technical Framework for Adaptive Accessibility SupportACCESS:  A Technical Framework for Adaptive Accessibility Support
ACCESS: A Technical Framework for Adaptive Accessibility Support
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and Autership
 
Text parser based interaction
Text parser based interactionText parser based interaction
Text parser based interaction
 
SAD04 - Inheritance
SAD04 - InheritanceSAD04 - Inheritance
SAD04 - Inheritance
 
GRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityGRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and Radiosity
 
GRPHICS07 - Textures
GRPHICS07 - TexturesGRPHICS07 - Textures
GRPHICS07 - Textures
 
GRPHICS06 - Shading
GRPHICS06 - ShadingGRPHICS06 - Shading
GRPHICS06 - Shading
 
GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)
 
GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)
 
GRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationGRPHICS03 - Graphical Representation
GRPHICS03 - Graphical Representation
 
GRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsGRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D Graphics
 
GRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsGRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D Graphics
 
GRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationGRPHICS09 - Art Appreciation
GRPHICS09 - Art Appreciation
 
2CPP18 - Modifiers
2CPP18 - Modifiers2CPP18 - Modifiers
2CPP18 - Modifiers
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - Templates
 
2CPP14 - Abstraction
2CPP14 - Abstraction2CPP14 - Abstraction
2CPP14 - Abstraction
 

Recently uploaded

Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
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
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
+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
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 

Recently uploaded (20)

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
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-...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
+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...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

Structural Design Patterns Explained: Facade, Adapter, Flyweight & Composite

  • 2. Introduction  Structural design patterns emphasize relationships between entities.  These can be classes or objects.  They are designed to help deal with the combinatorial complexity of large object oriented programs.  These often exhibit behaviours that are not immediately intuitive.
  • 3. Structural Patterns  Common to the whole philosophy behind structural patterns is the separation between abstraction and implementation.  This is a good guideline for extensible design.  Structural patterns subdivide into two broad subcategories.  Class structural patterns  Where the emphasis is on the relationship between classes  Object structural patterns  The emphasis is on consistency of interaction and realization of new functionality.
  • 4. Façade  When a model is especially complex, it can be useful to add in an additional pattern to help manage the external interface of that model.  That pattern is called a façade.  A façade sits between the view/controller and provides a stripped down or simplified interface to complex functionality.  There are costs to this though in terms of coupling and cohesion.  A façade is a structural pattern.
  • 5. Façade  A façade provides several benefits  Makes software libraries easier to use by providing helper methods  Makes code more readable  Can abstract away from the implementation details of a complex library or collection of classes.  Can work as a wrapper for poorly designed APIs, or for complex compound relationships between objects.
  • 6. Façade Example public class FacadeExample { SomeClass one; SomeOtherClass two; SomeKindOfConfigClass three; public SomeOtherClass handleInput (String configInfo) { three = SomeKindOfConfigClass (configInfo) one = new SomeClass (configInfo); two = one.getSomethingOut (); return two; } }
  • 7. Façade Example public class FacadeExample { public SomeOtherClass handleInput (String configInfo) { return myFacade.doSomeMagic (configInfo); } } public class Facade { SomeClass one; SomeOtherClass two; SomeKindOfConfigClass three; public SomeOtherClass doSomeMagic (String configInfo) { three = SomeKindOfConfigClass (configInfo) one = new SomeClass (configInfo); two = one.getSomethingOut (); return two; } }
  • 8. Façade  The more code that goes through the façade, the more powerful it becomes.  If just used in one place, it has limited benefit.  Multiple objects can make use of the façade.  Greatly increasing the easy of development and reducing the impact of change.  All the user has to know is what needs to go in, and what comes out.  The façade hides the rest
  • 9. Downsides  This comes with a necessary loss of control.  You don’t really know what’s happening internally.  Facades are by definition simplified interfaces.  So you may not be able to do Clever Stuff when blocked by one.  Facades increase structural complexity.  It’s a class that didn’t exist before.  Facades increase coupling and reduce cohesion.  They often have to link everywhere, and the set of methods they expose often lack consistency
  • 10. The Adapter  The Adapter design pattern is used to provide compatibility between incompatible programming interfaces.  This can be used to provide legacy support, or consistency between different APIs.  These are also sometimes called wrappers.  We have a class that wraps around another class and presents an external interface.
  • 11. The Adapter  Internally, an adapter can be as simple as a composite object and a method that handles translations.  We can combine this with other design patterns to get more flexible solutions.  For example, a factory for adapters  Or adapters that work using the strategy pattern.  It is the combination of design patterns that has the greatest potential in design.
  • 12. Simple Example abstract class Shape { abstract void drawShape (Graphics g, int x1, int x2, int y1, int y2); } public class Adapter { private Shape sh; public void drawShape (int x, int y, int len, int ht, Graphics g) { sh.drawShape (g, x, x+ht, y, y+len); } }
  • 13. Adapters and Facades  What’s the difference between a façade and an adapter?  A façade presents a new simplified API to external objects.  An adapter converts an existing API to a common standard.  The Façade creates the programming interface for the specific combination of objects.  The adapter simply enforces consistency between incompatible interfaces.
  • 14. The Flyweight  Object oriented programming languages provide fine-grained control over data and behaviours.  But that flexibility comes at a cost.  The Flyweight pattern is used to reduce the memory and instantiation cost when dealing with large numbers of finely- grained objects.  It does this by sharing state whenever possible.
  • 15. Scenario  Imagine a word processor.  They’re pretty flexible. You can store decoration detail on any character in the text.  How is this done?  You could represent each character as an object.  You could have each character contain its own font object…  … but that’s quite a memory overhead.  It would be much better if instead of holding a large font object, we held only a reference to a font object.
  • 16. The Flyweight  The Flyweight pattern comes in to reduce the state requirements here.  It maintains a cache of previously utilised configurations or styles.  Each character is given a reference to a configuration object.  When a configuration is applied, we check the cache to see if it exists.  If it doesn’t, it creates one and add it to the cache.  The Flyweight dramatically reduces the object footprint.  We have thousands of small objects rather than thousands of large objects.
  • 17. Before and After public class MyCharacter { char letter; Font myFont; void applyDecoration (string font, int size); myFont = new Font (font, size); } } public class MyCharacter { char letter; Font myFont; void applyDecoration (string font, int size); myFont = FlyweightCache.getFont (font, size); } }
  • 18. Implementing a Flyweight  The flyweight patterns makes no implementation assumptions.  A reasonably good way to do it is through a hash map or other collection.  Standard memoization techniques can be used here.  When a request is made, check the cache.  If it’s there, return it.  If it’s not, create it and put it in the cache and return the new instance.
  • 19. Limitations of the Flyweight Pattern  Flyweight is only an appropriate design pattern when object references have no context.  As in, it doesn’t matter to what they are being applied.  A font object is a good example.  It doesn’t matter if it’s being applied to a number, a character, or a special symbol.  A customer object is a bad example.  Each customer is unique.
  • 20. The Composite Pattern  We often have to manipulate collections of objects when programming.  The composite pattern is designed to simplify this.  Internally, it represents data as a simple list or other collection.  Requires the use of polymorphism to assure structural compatability.  Externally it presents an API to add and remove objects.  And also to execute operations on the collection as a whole.
  • 21. The Composite Pattern public class ShapeCollection implements Shape() { ArrayList shapes = new ArrayList(); void addShape (Shape s) { shapes.Add (s); } void removeShape (Shape s) { shapes.Remove (s); } void draw() { foreach (Shape s in shapes) { s.draw(); } } void setColour (Colour c) { foreach (Shape s in shapes) { s.setColour (c); } } }
  • 22. The Composite Pattern public MainProgram() { Circle circle = new Circle(); Rectangle rect = new Rectangle(); Triangle tri = new Triangle(); ShapeCollection myCollection = new ShapeCollection(); ShapeCollection overallScene = new ShapeCollection(); myCollection.addShape (circle); myCollection.addShape (rect); overallScene.addShape (myCollection); overallScene.addShape (tri); myCollection.setColour (Colour.RED); overallScene.draw(); }
  • 23. Why Use Composite?  Sometimes we need to be able to perform operations on groups of objects as a whole.  We may wish to move a group of shapes in a graphics package as one example.  These often exist side by side with more primitive objects that get manipulated individually.  Having handling code for each of these conditions is bad design.
  • 24. The Composite  The composite allows us to treat collections and individual objects through one consistent interface.  We don’t need to worry about which we are dealing with at any one time.  It works by ensuring that the collection implements the common interface shared by all its constituent bits.  The relationship is recursive if done correctly.
  • 25. Summary  Structural patterns are the last of the families of design patterns we are going to look at.  We use an adapter to deal with incompatible APIs.  We use a bridge to decouple abstraction from implementation.  Implementation is very similar to strategy, only the intent is unique.  Flyweight patterns are used to reduce processing and memory overheads.  Composites are used to allow recursive and flexible aggregate manipulation of objects.