几年前看的《大话设计模式》从书中学到了不少,而且讲解诙谐幽默。感谢作者能出版这样的书籍。
现在刚使用UML,这篇文章帮我快速入门《
聊聊.net程序设计——浅谈使用VS2010建模拓展(上)
从而想把其中的一些设计模式用UML做出来
为了有一个清晰的结构,一种设计模式放入一个UML类图;并且要在一个命名空间下(方便生成的类库改写)。为了实现这样的效果在模型中加入了包
生成后的类库结构
针对在UML模型的制作过程中遇到的问题做以下说明
策略模式时 CashSuper 与 CashContext 聚合后使用系统默认设置时生成的代码
namespace DesignPattern.Strategy
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class CashContext
{
public virtual CashSuper cs
{
get;
set;
}
public CashContext(CashSuper csuper)
{
}
public virtual double GetResult(double money)
{
throw new System.NotImplementedException();
}
}
}
这样的代码并不是想得到了,不得不进行设置
第二角色 Is Derived 设置为True, Visibility 设置为private , 可导航设置为True。方法GetResult(double money) 操作 Is Leaf 设置为True
得到代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class CashContext
{
private CashSuper cs
{
get;
set;
}
public CashContext(CashSuper csuper)
{
}
public double GetResult(double money)
{
throw new System.NotImplementedException();
}
}
当进行到代理模式时,接口无法正常生成代码。不得不再建立了一个模型项目结构基本相同只是包做了改变,所以命名空间也改变了
在制作到“Builder”模式时窗口无法显示绘制的图形,查资料得到
窗体重绘时,引发Paint事件,应该在Paint事件中画图,窗体改动和重启仍然有图形。如果放在Load事件中,绘图后随着窗体启动消失了。所以加入了按钮,效果图