Flyweight An Object Structural Design Pattern JM Imbrescia.

Slides:



Advertisements
Similar presentations
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
Advertisements

Flyweight: Structural Pattern Prepared by Galina Walters.
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
C15: Design Patterns Gamma,Helm,Johnson,Vlissides (GOF)
INTERPRETER Main Topics What is an Interpreter. Why should we learn about them.
Imagine that you need to create a system to represent all of the cars in a city. You need to store the details about each car ( model, and year) and the.
Prototype Pattern Creational Pattern Specify the kinds of objects to create using a prototypical instance, and create new objects by copy this prototype.
Software Design & Documentation – Design Pattern: Command Design Pattern: Command Christopher Lacey September 15, 2003.
The Flyweight Pattern Nik Reiman Joshua Hertz. Roadmap What is the Flyweight Pattern? UML When is Flyweight Useful? How to Use the Flyweight Pattern?
Cache Memory Ross Galijan. Library analogy Imagine a library, whose shelves are lined with books Problem: While one person can walk around the library.
Design Patterns I 1. Creational Pattern Singleton: intent and structure Ensure a class has one instance, and provide a global point of access to it 2.
Prototype Pattern Intent:
Algorithm Programming Structural Design Patterns Bar-Ilan University תשס " ו by Moshe Fresko.
DOCUMENT MANAGEMENT ZETA ERP.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Prototype Creational Design Pattern By Brian Cavanaugh September 22, 2003 Software, Design and Documentation.
Interpreter By: Mahmoodreza Jahanseir Amirkabir University of Technology Computer Engineering Department Fall 2010.
Katie C. O’Shea Dennis T. Tillman 11 February 2K2 Flyweight.
The Interpreter Pattern. Defining the Interpreter Intent Given a language, define a representation for its grammar along with an interpreter that uses.
1 PH Chapter 1 (pp. 1-10) GoF Composite Pattern (pp ) PH Ch 2 through Fundamentals (pp ) Presentation by Julie Betlach 5/28/2009.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
1 GoF Template Method (pp ) GoF Strategy (pp ) PH Single User Protection (pp ) Presentation by Julie Betlach 6/08/2009.
Design Pattern Interpreter By Swathi Polusani. What is an Interpreter? The Interpreter pattern describes how to define a grammar for simple languages,
Strategy Design Patterns CS 590L - Sushil Puradkar.
VIRTUAL MEMORY By Thi Nguyen. Motivation  In early time, the main memory was not large enough to store and execute complex program as higher level languages.
Computing IV Singleton Pattern Xinwen Fu.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
GoF: Document Editor Example Rebecca Miller-Webster.
Structural Design Patterns
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns V More Structural Patterns.
02 - Structural Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
Team 6 “The Unparseables” Design Patterns Chain of Responsibility Observer Flyweight 1.
Title Carolina First Steering Committee October 9, 2010 Online Voting System Design Yinpeng Li and Tian Cao May 3, 2011.
Prototype pattern Participants Prototype (Graphic) – declared an interface for cloning itself ConcretePrototype (EditBox, Slider) – implements an operation.
Proxy, Observer, Symbolic Links Rebecca Chernoff.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Billy Bennett June 22,  Intent Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.
The Interpreter Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The State Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Decorator Pattern (Structural) ©SoftMoore ConsultingSlide 1.
The Flyweight Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Design Patterns: Structural Design Patterns General and reusable solutions to common problems in software design Software University
Interpreter By: Mahmoodreza Jahanseir Amirkabir University of Technology Computer Engineering Department Fall 2010.
PROTOTYPE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
The State Design Pattern A behavioral design pattern. Shivraj Persaud
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
Software Design and Architecture Muhammad Nasir Structural Design Patterns
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Describe ways to assemble objects to implement a new functionality
Design Patterns Lecture part 2.
Factory Patterns 1.
Software Design and Architecture
Flyweight Design Pattern
Introduction to Computers
Object Pool Pattern 1.
Decorator Intent Also known as Wrapper Example: a Text Window
AtL: Thinking and Reflection
Interpreter Pattern.
Flyweight Pattern 1.
Read Two Ways.
Structural Patterns: Adapter and Bridge
Strategy Design Pattern
Understanding Your Organization for Process Analysis
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Flyweight An Object Structural Design Pattern JM Imbrescia

Intent “Use Sharing to support large numbers of fine- grained objects efficiently.” “Use Sharing to support large numbers of fine- grained objects efficiently.” Simply put, a method for storing a small number of complex objects that are used repeatedly. Simply put, a method for storing a small number of complex objects that are used repeatedly.

Motivation (Why use the Flyweight Pattern?) If you have an application that would benefit from using objects throughout your design. If you have an application that would benefit from using objects throughout your design. –Document Editors –50 Decks of cards

Definitions Flyweight Flyweight –A shared object that can be used in multiple contexts simultaneously. Intrinsic Intrinsic –State information that is independent of the flyweights context. Shareable Information. Extrinsic Extrinsic –State information that depends on the context of the flyweight and cannot be shared.

Applicability Use the Flyweight when all of the following are true: Use the Flyweight when all of the following are true: –Application has a large number of objects. –Storage costs are high because of the large quantity of objects. –Most object state can be made extrinsic. –Many groups of objects may be replaced by relatively few once you remove their extrinsic state. –The application doesn’t depend on object identity.

Participants Flyweight Flyweight ConcreteFlyweight ConcreteFlyweight UnsharedConcreeteFlyweight UnsharedConcreeteFlyweight FlyweightFactory FlyweightFactory Client Client

Image from the book thanks to:

Consequences Flyweights introduce runtime costs, these costs need to be offset by storage space savings. Savings come from: Flyweights introduce runtime costs, these costs need to be offset by storage space savings. Savings come from: –Fewer total instances due to sharing. –Increasing intrinsic space per object. –Computing extrinsic state instead of storing it.

Related Patterns Often combined with the Composite pattern. Often combined with the Composite pattern. State and Strategy objects are often implemented as flyweights. State and Strategy objects are often implemented as flyweights.