`
dr2tr
  • 浏览: 138724 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Design Patterns -- Flyweight

阅读更多

The intent of Flyweight is to use sharing to support large numbers of fine-grained objects efficiently. see pic:

 

A preliminary step in applying the Flyweight pattern is to extract the immutable part of an object so that this part can be shared. The class's immutablity relies on the immutability of its attributes. (Maybe the attributs will not change once the object is created)

Extracting the immutable part of an object is half of the battle in applying the Flyweight pattern. The remaining work includes creating a flyweight factory that instantiates flyweights and that arranges for clients to share them. And we also have to ensure that clients must use our factory instead of the constractor (use protected access of constructor and make another factory class in the same package).

To ensure that the factory class  is absolutely the only class that can create new instances, we can apply an inner class, define the class of the object in the factory class. (And make the former one static member class.)

 

分享到:
评论

相关推荐

    Packt.Go.Design.Patterns.2017

    Structural Patterns - Proxy, Facade, Decorator, and Flyweight Design Patterns Chapter 5. Behavioral Patterns - Strategy, Chain of Responsibility, and Command Design Patterns Chapter 6. Behavioral ...

    Design.Patterns.Explained.Simply

    We've tried hard to avoid both of these categories with Design Patterns Explained Simply. This book is fast and simple way to get the idea behind each of the 29 popular design patterns. The book is ...

    Design Patterns Elements of Reusable Object-Oriented Software

    • How Design Patterns Solve Design Problems • How to Select a Design Pattern • How to Use a Design Pattern A Case Study: Designing a Document Editor • Design Problems • Document Structure ...

    Beginning SOLID Principles and Design Patterns for ASP.NET Developers.pdf

    ■Chapter 6: Structural Patterns: Façade, Flyweight, and Proxy ■Chapter 7: Behavioral Patterns: Chain of Responsibility, Command, Interpreter, and Iterator ■Chapter 8: Behavioral Patterns: Mediator...

    Apress.Pro.Design.Patterns.in.Swift

    Pro Design Patterns in Swift shows you how to harness the power and flexibility of Swift to apply the most important and enduring design patterns to your applications, taking your development ...

    《Java Design Patterns》高清完整英文PDF版

    Chapter 16: Flyweight Patterns Chapter 17: Abstract Factory Patterns Chapter 18: Mediator Patterns Chapter 19: Prototype Patterns Chapter 20: Chain of Responsibility Patterns Chapter 21: Composite ...

    design patterns elements of reusable object-oriented software

    ★附录A介绍了剩下的设计模式:Bridge(桥接)、Builder(生成器)、Chainof Responsibility(责任链)、Flyweight(蝇量)、Interpreter(解释器)、Mediator(中介者)、Memento(备忘录)、Prototype(原型)、...

    Head First Design Patterns 英文版 Head First设计模式

    《Head First Design Patterns》编辑推荐:强大的写作阵容。《Head First Design Patterns》作者Eric Freeman;ElElisabeth Freeman是作家、讲师和技术顾问。Eric拥有耶鲁大学的计算机科学博士学位,E1isabath拥有...

    Head First Design Patterns 高清英文版

    至于第14章则很快地浏览尚未介绍的设计模式,包括Bridge、Builder、Chain of Responsibility、Flyweight、Interpreter、Mediator、Memento、Prototype,Visitor。第1章还介绍了四个○○基本概念(抽象、封装、继承、...

    Head First Design Patterns

    Flyweight、Interpreter、Mediator、Memento、Prototype、Visitor。第1章还介绍了四个OO基本概念(抽象、封装、继承、多态),而第1章到第9章也陆续介绍了九个OO原则(Principle)。 千万不要轻视这些OO原则,因为...

    管理系统javasal源码-Design-Patterns-Demo:超全的设计模式——理论+实现demo

    管理系统java sal源码 [toc] 设计模式 源码地址: 博客地址: 分类 序号 模式 & ...创建型模式:这些设计模式提供了一种在创建对象的同时隐藏创建逻辑...Pattern)享元模式(Flyweight Pattern)代理模式(Proxy Pattern)

    100-words-design-patterns-java:GoF设计模式,每个模式都描述了真实生活中的故事

    官方网站: Java中的100个单词GoF设计模式 介绍 想法:以一种简单的方式描述GoF设计模式。每个模式将通过以下结构进行描述: 故事(少于100个字) 用Java实现 GoF设计模式 创作模式 结构模式 ...

    Design Patterns by Tutorials 2nd Edition.zip

    This 23-chapter book starts with basic patterns like MVC, Delegate and Strategy, and then moves into more advanced patterns such as the Factory, Prototype, Multicast Delegate, Flyweight, Command, and ...

    Head First Design Patterns(英文,无水印,完整版)

    本书荣获2005年第十五届Jolt通用类图书震撼大奖。 本书英文xx版被《程序员》等机构评选为2006...至于第14章则很快地浏览尚未介绍的设计模式,包括Bridge、Builder、Chain of Responsibility、Flyweight、Interpreter、

    Java.Design.Patterns.1537192353

    Java design patterns with the Simplest real world examples which are easy to understand & remember as well. Table of Contents PREFACE ABOUT DESIGN PATTERNS SINGLETON PATTERN FACTORY PATTERN ABSTRACT ...

    Game Programming Patterns(游戏设计模式).2016

    Design Patterns Revisited 2. Command 3. Flyweight 4. Observer 5. Prototype 6. Singleton 7. State III. Sequencing Patterns 8. Double Buffer 9. Game Loop 10. Update Method IV. Behavioral Patterns 11. ...

    head first design patterns 英文原版高清

    至于第14章则很快地浏览尚未介绍的设计模式,包括Bridge、Builder、ChainofResponsibility、Flyweight、Interpreter、Mediator、Memento、Prototype,Visitor。第1章还介绍了四个基本概念(抽象、封装、继承、多态),...

    designPatterns:设计模式

    design pattern 设计模式 创建型设计模式 创建型模式设计到将对象实例化,这类模式都提供了一个方法,将客户从所需要的实例化对象中解耦。 原型模式 Prototype 结构型设计模式 结构型模式可以让你把类或者对象组合到...

    oh-my-design-patterns::artist_palette:记录我在学习设计模式时编写的文章和代码

    Oh, my design patterns记录了我学习设计模式时写的文章以及代码。若有纰漏,欢迎指正与交流。:grinning_face:点击查看电子书,体验更好 :backhand_index_pointing_right: 创建型 (Creational)Java Kotlin结构型...

    Benning.Game.Programming.Patterns

    You'll dive deep into how scripting engines encode behavior, how quadtrees and other spatial partitions optimize your engine, and how other classic design patterns can be used in games. Table of ...

Global site tag (gtag.js) - Google Analytics