Flyweight Design Pattern

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Advertisements

GoF State Pattern Aaron Jacobs State(305) Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
Flyweight: Structural Pattern Prepared by Galina Walters.
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.
Flyweight An Object Structural Design Pattern JM Imbrescia.
Design Patterns CS is not simply about programming
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
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.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Algorithm Programming Structural Design Patterns Bar-Ilan University תשס " ו by Moshe Fresko.
Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Katie C. O’Shea Dennis T. Tillman 11 February 2K2 Flyweight.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
Design Pattern Interpreter By Swathi Polusani. What is an Interpreter? The Interpreter pattern describes how to define a grammar for simple languages,
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Computing IV Singleton Pattern Xinwen Fu.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), 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.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
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.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Billy Bennett June 22,  Intent Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.
Design Patterns Introduction
The State Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Flyweight Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Presented by FACADE PATTERN
Design Patterns: MORE Examples
Abstract Factory Pattern
Unit II-Chapter No. : 5- design Patterns
Factory Method Pattern
Jim Fawcett CSE776 – Design Patterns Summer 2005
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
The Object-Oriented Thought Process Chapter 15
Chapter 10 Design Patterns.
Software Design Patterns
Design Patterns Lecture part 2.
Introduction to Design Patterns
Design Patterns Introduction
Software Design and Architecture
Software Design and Architecture
Factory Method Pattern
Abstract Factory Pattern
Design Patterns - A few examples
Advanced Programming Behnam Hatami Fall 2017.
Decorator Intent Also known as Wrapper Example: a Text Window
Design Patterns in Game Design
Jim Fawcett CSE776 – Design Patterns Summer 2003
State Design Pattern 1.
Design Patterns Satya Puvvada Satya Puvvada.
Interpreter Pattern.
Flyweight Pattern 1.
Strategy Design Pattern
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Composite Design Pattern By Aravind Reddy Patlola.
Adapter Pattern Jim Fawcett
Iterator Design Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014
Adapter Pattern Jim Fawcett
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Flyweight Design Pattern Cse 776 design patterns Summer ‘10 Bharath setty Dr. James fawcett

Intent “Use sharing to support large numbers of fine-grained objects efficiently.” One object instance holding shared (intrinsic) state Unique (extrinsic) state is stored outside of the shared object

Motivation Folder Representation

Forces Problem Context Forces Solution Benefits Consequences Related Patterns John Reekie (UTS)

Forces To obtain a fine grained object structure We will possibly have many objects Cost of storing a copy of each object is high

Motivation Example Folder Representation

flyweight pattern is used when all of the following are true Applicability flyweight pattern is used when all of the following are true An application has a large number of objects Store costs are high Most object state can be made extrinsic??? Authors claim. I strongly disagree You want most of object state intrinsic, e.g., shared Many groups of objects will be replaced by few shared objects(intrinsic) The application doesn’t depend on object identity

Structure

Participants Flyweight (Window) Declares interface that flyweights can use to receive and act on intrinsic state ConcreteFlyweight (Icon) Implements flyweight interface and adds storage for intrinsic state. Must be shareable UnsharedConcreteFlyweight (Name, Location) Commonly has ConcreteFlyweights as children Flyweightfactory Creates and manages flyweight objects Client Maintains references to flyweights Computes or stores extrinsic state of flyweights

Application

Collaborations State of Flyweight is characterized by intrinsic and extrinsic state Intrinsic state stored in ConcreteFlyweight Extrinsic state stored or computed by Client Objects Clients should not instantiate ConcreteFlyweights directly Proper sharing will not occur

Consequences Pros: Cost saved by space savings (Function of reduction of number of instances and amount of intrinsic state per object) Cons: Cost increased in run-time to transfer, find or compute extrinsic state

Implementation Removing Extrinsic State Must be easily identifiable and be removed from shared objects Pattern is only useful if state can be shared Managing Shared Objects Clients should not instantiate ConcreteFlyweights directly Flyweight factory allows clients to locate a particular flyweight Reference counting and garbage collection can be used

Known Uses 2D/3D Vector drawing program 2D/3D Video game Cad applications

Related Patterns Flyweight is often combined with Composite pattern to implement a logically hierarchical structure in terms of a graph with shared leaf nodes State and Strategy can be implemented as flyweights State: An object can alter its behavior when its internal state changes Strategy: Define a family of algorithms and make them interchangeable

References Design Patterns, Elements of Reusable Object-Oriented Software, Erich Gamma, et. al. http://www.informit.com/articles/article.aspx?p=31563&seqnum=3 http://sourcemaking.com/design_patterns/flyweight http://www.xml.com/pub/a/2000/01/19/feature/index.html?page=3 http://www.blackwasp.co.uk/flyweight.aspx http://www.ecs.syr.edu/faculty/fawcett/handouts/cse776/presentations-students/flyweight/

Questions????