结构型模式-享元
来源:互联网 发布:网络bng什么意思 编辑:程序博客网 时间:2024/05/18 01:49
结构图
模式说明
类设计
模式说明
- 扩展点在享元接口Flyweight的实现类。
- Flyweight的实现由共享和非共享两种,Condition作为外部条件封装,提供给Flyweight操作方法使用参数。
- 客户端不需要知道具体使用哪个Flyweight实现,只需要根据key按需取用即可。
- 运用享元可有效支持大量细粒度的对象。
public static void main(String[] args) {Condition condition = new Condition();FlyweightFactory ff = new FlyweightFactory();Flyweight fx = ff.getFlyweight("X");fx.operation(condition);Flyweight fy = ff.getFlyweight("Y");fy.operation(condition);Flyweight fz = ff.getFlyweight("Z");fz.operation(condition);Flyweight uf = new UnsharedConcreteFlyweight();uf.operation(condition);}
类设计
public interface Flyweight {public void operation(Condition condition);}public class ConcreteFlyweight implements Flyweight {@Overridepublic void operation(Condition condition) {System.out.println("concrete operation:" + condition);}}public class UnsharedConcreteFlyweight implements Flyweight {@Overridepublic void operation(Condition condition) {System.out.println("unshared concrete operation:" + condition);}}public class FlyweightFactory {private Map<String, Flyweight> flyweights = new HashMap<String, Flyweight>();public FlyweightFactory() {flyweights.put("X", new ConcreteFlyweight());flyweights.put("Y", new ConcreteFlyweight());flyweights.put("Z", new ConcreteFlyweight());}public Flyweight getFlyweight(String key) {return flyweights.get(key);}}public class Condition {}
0 0
- 结构型模式-享元
- 设计模式-结构型模式-享元
- 设计模式--结构型--享元模式
- 结构型模式-享元模式
- 享元模式-对象结构型模式
- 结构型模式--享元模式
- 结构型模式-Flyweight ( 享元模式 )
- 享元模式 - 结构型模式
- 结构型设计模式-享元模式
- 结构型模式-享元模式
- 结构型设计模式-享元模式
- 结构模式->享元模式
- 结构型模式:Flyweight(享元)
- 【结构型模式】flyweight(享元)
- 享元模式(结构型)
- 2.结构型.7.享元模式
- 享元模式(结构型)
- 9-结构型-享元模式
- netstat统计的tcp连接数与⁄proc⁄pid⁄fd下socket类型fd数量不一致的分析
- 【Jason's_ACM_解题报告】Trees on the level
- Security Analytics: Detecting Advanced Threats and Fraud
- hdu 2602 Bone Collector
- Hibernate中使用多对多映射注解
- 结构型模式-享元
- Oracle 数据库服务器使用aix小机,并且该小机作为nfs client使用的一级挂载点问题
- 【Jason's_ACM_解题报告】Tree
- bzoj 2301 Problem b 莫比乌斯反演+容斥
- (lazarus)用BGRABitmap对chart进行反锯齿,效果对比
- POJ 3190 - Stall Reservations(贪心)
- 【Jason's_ACM_解题报告】Not so Mobile
- (hdu step 4.2.3)Rescue(求从起点到终点的最少步数,遇到特殊节点需要耗时2秒)
- IOS 自定义控件之UIActivityIndicatorView