设计模式 之 创建者

很久没写设计模式学习笔记了,今天无聊,随便把以前看的模式的都写下.

先把代码帖上来吧.

这个模式,是模拟 西山居的一款游戏,剑侠情缘 来写的,呵呵,当然,该游戏到底是怎么设计的,我是不知道,只是作为一个例子放到这个地方.

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace 建造者
{
    public interface 地图
    {
        路 路
        {
            get;
            set;
        }
        树 树
        {
            get;
            set;
        }

        Color MainColor
        {
            get;
            set;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
    public class 长白山南麓 : 地图
    {

        private 路 tempRoad;
        public 路 路
        {
            get
            {
                return tempRoad;
            }
            set
            {
                tempRoad = value;
            }
        }

        private 树 tempTree;
        public 树 树
        {
            get
            {
                return tempTree;
            }
            set
            {
                tempTree = value;
            }
        }

        private System.Drawing.Color tempMainColor;
        public System.Drawing.Color MainColor
        {
            get
            {
                return tempMainColor;
            }
            set
            {
                tempMainColor = value;
            }
        }

       
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
    public interface 路
    {
        double Width
        {
            get;
            set;
        }

        double Height
        {
            get;
            set;
        }

        System.Drawing.Color Color
        {
            get;
            set;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
    public class 水泥路 : 路
    {
        #region 路 Members

        public double Width
        {
            get
            {
                throw new Exception("The method or operation is not implemented.");
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }

        public double Height
        {
            get
            {
                throw new Exception("The method or operation is not implemented.");
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }

        public System.Drawing.Color Color
        {
            get
            {
                throw new Exception("The method or operation is not implemented.");
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }

        #endregion
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
    public interface 树
    {
        System.Drawing.Color Color
        {
            get;
            set;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
    public class 梧桐树 : 树
    {
        #region 树 Members

        public System.Drawing.Color Color
        {
            get
            {
                throw new Exception("The method or operation is not implemented.");
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }

        #endregion
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
    public interface 地图创建
    {
        void 创建路();

        void 创建树();

        void 设置颜色();

        地图 地图对象();   
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
    public class 长白山南麓地图创建 : 地图创建
    {
        private 地图 长白山南麓地图;
        public 长白山南麓地图创建()
        {
            长白山南麓地图 = new 长白山南麓();
        }

        public void 创建路()
        {
            路 长白山南麓的路 = new 水泥路();
            长白山南麓地图.路 = 长白山南麓的路;
        }

        public void 创建树()
        {
            树 长白山南麓的树 = new 梧桐树();
            长白山南麓地图.树 = 长白山南麓的树;
        }

        public void 设置颜色()
        {
            长白山南麓地图.MainColor = System.Drawing.Color.White;
        }

        public 地图 地图对象()
        {
            return 长白山南麓地图;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace 建造者
{
 

 public class 系统
    {
        地图创建 地图创建;
        public 系统(地图创建 一个地图创建实例)
        {
            地图创建 = 一个地图创建实例;
        }

        public 地图 创建地图()
        {

            地图创建.创建路();

            地图创建.创建树();

            地图创建.设置颜色();

            return 地图创建.地图对象();
        }
    }


}


客户端调用:

 

            建造者.系统 建造者系统 = new 建造者.系统(new 建造者.长白山南麓地图创建());

          
            建造者.地图 长白山南麓地图 = 建造者系统.创建地图();



我很苦恼,按照这样的做法,怎么越来越象 工厂方法了.
呵呵,也不知道这个模式有没有写对.
先把代码放到这个地方,有时间在研究 创建者  和工厂方法的区别.

转载于:https://www.cnblogs.com/yanchanggang/archive/2007/12/18/1004225.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/464003.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

svn添加用户.sh

#!/bin/bash FLASH_SVNPATH/xx_new_flash/conf DESIGN_SVNPATH/xx_new_design/conf JAVA_SVNPATH/xx_new_java/conf echo "请选择 java flash meishucehua " read -p "请选择部门员工 java,flash,meishucehua " bumen case $bumen in flash) …

spring boot+mybatis+generator生成domain大小写问题

之前遇到一个问题&#xff0c;用generator生成数据库对应的domain&#xff0c;以前都是好好的&#xff0c;那天突然生成的domain都是小写的&#xff0c;因为我数据库里是大写的&#xff0c;后来找到解决办法&#xff0c; <table tableName"material_pile" domainO…

boost库学习入门篇

学习及使用Boost库已经有一段时间了&#xff0c;Boost为我的日常开发中带来了极大的方便&#xff0c;也使得我越来越依赖于boost库了。但boost功能太多&#xff0c;每次使用还是得翻看以前的 资料&#xff0c;所以为了以后可以更方便的使用&#xff0c;在此对常用的功能作一个…

开源 STM32 USB-CAN项目

照理来说&#xff0c;USB-CAN这种东西应该已经被做的烂大街的工具&#xff0c;国内居然没有一个拿得出手的开源方案。某立功和PCAN动辄2000的价格也是离谱。淘宝上各种虚拟串口方案、替换dll兼容某立功软件的各种方案....价格都倒是便宜&#xff0c;性能和可靠性嘛.......就不多…

Windows Workflow Foundation - [介绍及相关资源]

Workflow Foundation是能使你在Windows平台上快速构建工作流应用程序的编程模型&#xff0c;引擎以及工具。WF支持各种各样的工作流场景&#xff1a;包括以用户界面为中心的页面流程&#xff0c;文档为中心的工作流程&#xff0c;业务规则驱动的业务流程等。 如果你使用的是VS2…

Go语言web框架 gin

Go语言web框架 GIN gin是go语言环境下的一个web框架, 它类似于Martini, 官方声称它比Martini有更好的性能, 比Martini快40倍, Ohhhh….看着不错的样子, 所以就想记录一下gin的学习. gin的github代码在这里: gin源码. gin的效率获得如此突飞猛进, 得益于另一个开源项目httproute…

8位ADC是256还是255?

昨天的文章发了之后&#xff0c;有朋友找到我&#xff0c;给我讨论了很多关于ADC细节。晚上给个朋友在51上调ADC0808芯片有一个朋友是做硬件的&#xff0c;他有从事过专业仪器设备&#xff0c;常年有使用ADC的经验&#xff0c;他给我的观点是&#xff0c;8位ADC对应的就是256。…

WCF中使用HttpSession

在WCF中不能使用HttpSession&#xff0c;即使Host是IIS也不可以&#xff0c;这就造成在WEB应用中集成WCF不太方便&#xff0c;其实可以通过配置搞定&#xff0c;关键在于三点&#xff1a;Host、契约类、Client端。 Host上要求Web.config中有定义&#xff1a; <system.servic…

boost库在ubuntu下的安装

系统是ubuntu虚拟机&#xff0c;安装的是boost_1_60_0。 &#xff08;1&#xff09;首先去下载最新的boost代码包&#xff0c;网址www.boost.org。 &#xff08;2&#xff09;进入到自己的目录&#xff0c;解压&#xff1a; bzip2 -d boost_1_60_0.tar.bz2 tar xvf boost_1_…

Google的投票站点在用Asp.net

https://survey.google.com/wix/p0621608.aspx https://survey.google.com/aaaaaaaaaaaaaa.axd https://survey.google.com/wix/xxxxxxxxxxxxxxxxxxxxx.ashx Server Microsoft-IIS/6.0X-AspNet-Version 2.0.50727 X-Powered-By ASP.NET 转载于:https://ww…

所谓的0拷贝不就是为了让CPU休息吗?深入理解mmap

1.开场白环境&#xff1a;处理器架构&#xff1a;arm64内核源码&#xff1a;linux-5.11ubuntu版本&#xff1a;20.04.1代码阅读工具&#xff1a;vimctagscscope我们知道&#xff0c;linux系统中用户空间和内核空间是隔离的&#xff0c;用户空间程序不能随意的访问内核空间数据&…

Python3 B格注释

看tornado源码&#xff0c;看到一些函数定义时的不解的地方&#xff0c;查了一通&#xff0c;原来是注释。 冒号注释变量&#xff0c;箭头注释函数&#xff1b; 例子如下 Python3环境下&#xff0c;执行以下代码。 def a(x:这是X变量) -> for test: print(x) 转载于:https:/…

Java多线程同步Synchronized使用分析

同步的概念&#xff1a; 同步分为 同步方法 和 同步块 两种方式。 锁定的内容分为 锁定类的某个特定实例 和 锁定类对象(类的所有实例) 变量分为 实例变量(不带static的变量) 和 类变量(带static的变量) 使用同步的原因 1. 在系统中对访类要使用多线程进行访问; 2. 在该类中有 …

boost::function的用法(一)

boost::function的用法 本片文章主要介绍boost::function的用法。 boost::function 就是一个函数的包装器(function wrapper)&#xff0c;用来定义函数对象。 1. 介绍 Boost.Function 库包含了一个类族的函数对象的包装。它的概念很像广义上的回调函数。其有着和函数指针相同的…

nhibernate学习之集合组合依赖

1.学习目标还是学习compenent的用法&#xff0c;上节实现了简单字段的组合&#xff0c;这节中将讨论两个问题&#xff1a;1.依赖对象有一个指向容器对象的引用。2。集合依赖2.开发环境和必要准备开发环境为:windows 2003,Visual studio .Net 2005,Sql server 2005 developer ed…

追更这个做嵌入式的大佬

在知乎上看到一个做嵌入式91年小年轻&#xff0c;分享给大家在他看来&#xff0c;嵌入式也是一个很吃香的技术&#xff0c;在周末写这篇文章的时候&#xff0c;也刚收到一个朋友的微信消息&#xff0c;他说自己拿到了70多万的年包offer。大家想追更作者的原文&#xff0c;可以点…

CentOS6.5安装ElasticSearch6.2.3

CentOS6.5安装ElasticSearch6.2.3 1、Elastic 需要 Java 8 环境。&#xff08;安装步骤&#xff1a;http://www.cnblogs.com/hunttown/p/5450463.html&#xff09; 2、安装包下载&#xff1a; #官网地址 https://www.elastic.co/downloads/elasticsearch 3、新建用户 Elastic高…

C#中跨窗体操作(1)--事件

在应用C#过程中&#xff0c;经常会出现通过“窗口2”来处理“窗口1”上的控件和显示内容等。可以通过事件的处理方式来完成&#xff0c;具体步骤如下&#xff1a; 1、在“窗体2”中声明事件 public delegate void Change(); public event Change myChangeevent; 2、编写…

boost中bind的使用

最近对boost的bind部分比较感兴趣&#xff0c;对其背后的机制进行了简单的分析&#xff0c;和大家分享一下。 注&#xff0c;我所看的代码是boost_1_64_0&#xff0c; 想来各个版本的差异不大。 定义函数 [cpp] view plaincopy int f(int a, int b) { return a b; }…

这道字符串反转的题目,你能想到更好的方法吗?

周末有一个朋友问了一个笔试题目&#xff0c;当时还直播写了答案&#xff0c;但是总觉得写得不够好&#xff0c;现在把题目放出来。大家看看有没有什么更好的解法题目有一个字符串&#xff0c;如下&#xff0c;要求对字符串做反转后输出//input the sky is blue//output blue …