文件名称:Visitor
-
所属分类:
- 标签属性:
- 上传时间:2008-10-13
-
文件大小:85.81kb
-
已下载:0次
-
提 供 者:
-
相关连接:无下载说明:别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容来自于网络,使用问题请自行百度
设计模式——访问者模式
Visitor模式允许我们在不改动原有结构的基础之上不断增加新的功能。
ICumulation接口定义了方法Cumulate(),旨在计算1+2+……+n,有两种不同的实现方法,一个是一般的叠加算法GeneralArithmetic,一个是高斯算法GaoSiArithmetic。
因为某种原因,系统需要添加求平均值的功能,还有计算1到n的平方和。
按照一般的思路,我们需要在ICumulation中定义两个方法分别计算平均值和平方和,并在实现类中同时添加相应的方法。在搭建了visitor模式的架构以后,添加功能的代码被移植到ICumulationVisitor中,添加的两种功能也分别被以子类AverageVisitor和PowerVisitor实现。
功能的扩展从在类中添加方法的方式变成了添加新类的方式,该类继承一定的Visitor接口。这是一个90度的转换,使得架构符合开放封闭(OCP)原则:功能的扩展无需改动原有代码。
同时,这里也体现了单一职责原则(SRP),ICumulation层次结构可以因为出现了不同的算法而改变,但是不应该因为需要计算不同的东西(功能)而改变,算法和功能是横向和纵向的关系。这里visitor模式隔离了算法和功能,ICumulation层次结构负责算法,ICumulationVisitor层次结构负责功能。-design patterns -- Visitor visitors model allows us to model without changing the original structure on the basis of constantly adding new features. ICumulation interface definition of the method Cumulate (), designed to calculate a +2 + ... + n, there are two different method, a general superposition GeneralArithmetic algorithm, is a Gaussian algorithms GaoSiArithmetic. For some reason, the system needs to add functions for the average, there is a calculation of n and the square. As a general idea, we need to define ICumulation two methods were calculated and the average square, and in achieving category by adding the corresponding method. The erection of a visitor model, after adding functional code are transferred to ICumulationVisitor, adding the two functions were also a subclass Aver
Visitor模式允许我们在不改动原有结构的基础之上不断增加新的功能。
ICumulation接口定义了方法Cumulate(),旨在计算1+2+……+n,有两种不同的实现方法,一个是一般的叠加算法GeneralArithmetic,一个是高斯算法GaoSiArithmetic。
因为某种原因,系统需要添加求平均值的功能,还有计算1到n的平方和。
按照一般的思路,我们需要在ICumulation中定义两个方法分别计算平均值和平方和,并在实现类中同时添加相应的方法。在搭建了visitor模式的架构以后,添加功能的代码被移植到ICumulationVisitor中,添加的两种功能也分别被以子类AverageVisitor和PowerVisitor实现。
功能的扩展从在类中添加方法的方式变成了添加新类的方式,该类继承一定的Visitor接口。这是一个90度的转换,使得架构符合开放封闭(OCP)原则:功能的扩展无需改动原有代码。
同时,这里也体现了单一职责原则(SRP),ICumulation层次结构可以因为出现了不同的算法而改变,但是不应该因为需要计算不同的东西(功能)而改变,算法和功能是横向和纵向的关系。这里visitor模式隔离了算法和功能,ICumulation层次结构负责算法,ICumulationVisitor层次结构负责功能。-design patterns -- Visitor visitors model allows us to model without changing the original structure on the basis of constantly adding new features. ICumulation interface definition of the method Cumulate (), designed to calculate a +2 + ... + n, there are two different method, a general superposition GeneralArithmetic algorithm, is a Gaussian algorithms GaoSiArithmetic. For some reason, the system needs to add functions for the average, there is a calculation of n and the square. As a general idea, we need to define ICumulation two methods were calculated and the average square, and in achieving category by adding the corresponding method. The erection of a visitor model, after adding functional code are transferred to ICumulationVisitor, adding the two functions were also a subclass Aver
(系统自动生成,下载前可以参看下载内容)
下载文件列表
Visitor/code/App.ico
Visitor/code/AssemblyInfo.cs
Visitor/code/bin/Debug
Visitor/code/bin
Visitor/code/GaoSiArithmetic.cs
Visitor/code/GereralArithmetic.cs
Visitor/code/ICumulation.cs
Visitor/code/MainForm.cs
Visitor/code/MainForm.resx
Visitor/code/obj/Debug
Visitor/code/obj
Visitor/code/Visitor/AverageVisitor.cs
Visitor/code/Visitor/ICumulationVisitor.cs
Visitor/code/Visitor/PowerVisitor.cs
Visitor/code/Visitor
Visitor/code/Visitor.csproj
Visitor/code/Visitor.csproj.user
Visitor/code/Visitor.sln
Visitor/code/Visitor.suo
Visitor/code
Visitor/structure.vsd
Visitor/Visitor.txt
Visitor
www.dssz.com.txt
Visitor/code/AssemblyInfo.cs
Visitor/code/bin/Debug
Visitor/code/bin
Visitor/code/GaoSiArithmetic.cs
Visitor/code/GereralArithmetic.cs
Visitor/code/ICumulation.cs
Visitor/code/MainForm.cs
Visitor/code/MainForm.resx
Visitor/code/obj/Debug
Visitor/code/obj
Visitor/code/Visitor/AverageVisitor.cs
Visitor/code/Visitor/ICumulationVisitor.cs
Visitor/code/Visitor/PowerVisitor.cs
Visitor/code/Visitor
Visitor/code/Visitor.csproj
Visitor/code/Visitor.csproj.user
Visitor/code/Visitor.sln
Visitor/code/Visitor.suo
Visitor/code
Visitor/structure.vsd
Visitor/Visitor.txt
Visitor
www.dssz.com.txt
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.