Visitor

所属分类:软件工程
开发工具:C#
文件大小:110KB
下载次数:10
上传日期:2006-06-03 23:41:00
上 传 者管理员
说明:  设计模式——访问者模式 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 (1078, 2005-09-16)
Visitor\code\AssemblyInfo.cs (1859, 2005-09-16)
Visitor\code\bin\Debug (0, 2005-09-16)
Visitor\code\bin (0, 2005-09-16)
Visitor\code\GaoSiArithmetic.cs (575, 2005-09-16)
Visitor\code\GereralArithmetic.cs (675, 2005-09-16)
Visitor\code\ICumulation.cs (235, 2005-09-16)
Visitor\code\MainForm.cs (9145, 2005-09-16)
Visitor\code\MainForm.resx (13883, 2005-09-16)
Visitor\code\obj\Debug (0, 2005-09-16)
Visitor\code\obj (0, 2005-09-16)
Visitor\code\Visitor\AverageVisitor.cs (684, 2005-09-16)
Visitor\code\Visitor\ICumulationVisitor.cs (291, 2005-09-16)
Visitor\code\Visitor\PowerVisitor.cs (1185, 2005-09-16)
Visitor\code\Visitor (0, 2005-09-16)
Visitor\code\Visitor.csproj (5778, 2005-09-16)
Visitor\code\Visitor.csproj.user (1805, 2005-09-16)
Visitor\code\Visitor.sln (899, 2005-09-16)
Visitor\code\Visitor.suo (9728, 2005-09-16)
Visitor\code (0, 2005-09-16)
Visitor\structure.vsd (131584, 2005-09-16)
Visitor\Visitor.txt (983, 2005-09-16)
Visitor (0, 2006-03-30)

近期下载者

相关文件


收藏者