设计模式 之 创建者
先把代码帖上来吧.
这个模式,是模拟 西山居的一款游戏,剑侠情缘 来写的,呵呵,当然,该游戏到底是怎么设计的,我是不知道,只是作为一个例子放到这个地方.
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
设计模式 之 创建者相关推荐
- 设计模式--依然创建者
读HeadFirst的工厂有一下几条小感悟,这几条是我之前看书时记录下来的,这次又复习了下.其实创建类型的模式的主要作用在于集中创建对象,用时调用所需,以及在相似类型的对象创建的便捷性提供了帮助. 其 ...
- 设计模式系列-创建者模式
为什么80%的码农都做不了架构师?>>> 一.上篇回顾 上篇我们主要讲述了抽象工厂模式和工厂模式.并且分析了该模式的应用场景和一些优缺点,并且给出了一些实现的思路和方案,我们现 ...
- 设计模式之创建者模式
设计模式的基本原则 设计模式体现的是软件设计的思想,而不是软件技术,它重在使用多态与抽象类来解决各种问题 开放封闭原则:类的改动是通过增加代码进行的,而不是修改源代码 依赖倒置原则:依赖于抽象(接口) ...
- 【设计模式】创建者模式(单例工厂原型建造者)
文章目录 1.单例设计模式 1.1 单例模式概述 1.2 单例模式的实现 1.2.1 饿汉式(静态变量方式) 1.2.2 饿汉式(静态代码块方式) 1.2.3 懒汉式(线程不安全) 1.2.4 懒汉式 ...
- java设计模式-Builder创建者模式
问题分析: Builder模式是一步一步创建一个复杂对象的创建型模式.该模式是为了将构建复杂对象的过程和他的部件解耦,使得构建过程和部件的表示隔离开来. Builder模式 主要用于"构建一 ...
- java 创建者设计模式_Java设计模式之创建者模式分享热爱编程,程序人生
PS:今天的23中设计模式中的创建者方式,至此告一段落.我今天带来的技术分享为创建者模式以及原型模式.当然在Java中这两种方式很常见,只不过我们写的次数确实有点低而已,但是这不是我不学它的借口!!! ...
- Java设计模式之创建者模式
1 简介 在最近看的一篇文章中,提到了关于新年目标制定的方式的实践,觉得不错,附在上图.尤其是目标一定要符合SMART模式, 为了-,通过-,截止-前,实现- 这个句式很有力量. 在日常编程实践中,对 ...
- 【设计模式】 - 创建者模式 - 工厂方法模式、抽象工程模式
工厂方法模式.抽象工程模式 前言 工厂方法模式. 抽象工程模式 1. 简单工厂模式(不属于GOF的23种经典设计模式) 1.1 结构 1.2 实现 缺点 2. 工厂方法模式 2.1 结构 2.2 实现 ...
- 设计模式学习笔记总结
设计模式七大原则 单一职责原则 对于一个类应该只负责一项职责. 接口隔离 客户端不应该依赖它不需要的接口,即一个类对另一个类的依赖应该建立在最小接口上. 依赖倒转 高层模块不应该依赖底层模块,两者都应 ...
最新文章
- R语言aggregate函数数据聚合实战
- [置顶] 也论百度轻应用--一个开发者的吐槽
- MySQL工作中的实际用_数据库在工作中的应用,以及什么是MySQL?
- python代码检查工具_基于Python3的漏洞检测工具 ( Python3 插件式框架 )
- BOM validation - cannot find where this error message is raised
- 数学老师出的谜语,语文老师已哭晕在厕所!
- 调用API发送短信python
- C++之一个函数链的简单例子(分文件实现)
- doc 命令查看帮助
- mysql插入日期_MySQL 的两个特殊数据类型属性 unsigned与 zerofill
- 基于java的租房系统源代码_基于jsp的租房管理系统-JavaEE实现租房管理系统 - java项目源码...
- python面试题:python计算股票收益最大化
- python绘制中国_Python-Geopandas 教你绘制中国地图
- hp打印机计算机接口,hp打印机的端口怎么设置?各是什么意思?
- 手机怎么提高图片分辨率?手机怎么改照片分辨率dpi?
- 聚焦品牌化 Morketing2018第二届跨境出口电商营销峰会成功举办
- 中国省市区--地区SQL表
- 至简设计系列_电子密码锁
- JAVA三角形边长定义_Java编译:定义三角形的三条边长a=4,b=8.54,c=4.44;求三角形的周长d...
- 华子机试 计算足球赛比分 java