zoukankan      html  css  js  c++  java
  • 设计模式--原型模式

    原型模式 Prototype Pattern
    意图:使用原型实例定义/指定被创建对象种类/类型,通过拷贝原型实例创建新对象
    
    应用场景:
    1)当某个类指定在运行时实例化
    2)减少子类数量
    3)降低昂贵类型新对象创建成本
    
    好处或缺点:
    1)clone方法可能实现比较困难
    2)不适用于含循环引用的类结构
    
    类结构:
    参与者:client ,Prototype,ConcretePrototype
    prototype:定义原型的行为

        //关键代码
        class Notification implements cloneable
        {
            string title;
            string content;
            //seters
            Footer footer;
            Nofification clone() {
            //try catch
            // return (Notification)super.clone();
            }
        };
    怕什么真理无穷,进一寸有一寸的欢喜。---胡适
  • 相关阅读:
    Codeforces-859C Pie Rules(dp)
    Codeforces-550D Regular Bridge
    Codeforces-534D Handshakes
    抽象类
    内部类
    接口
    初始化
    this 和super
    数据库测试的测试点
    数据库测试的主要内容
  • 原文地址:https://www.cnblogs.com/hujianglang/p/7517996.html
Copyright © 2011-2022 走看看