Visitor 表示一个作用于某个对象结构中的各元素的操作。它使你可以在不改变各元素的类的前提下定义作用于这些元素的新操作
2007-01-17 13:41
591 查看
using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6
using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6
using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6
using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6
using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6
ObjectStructure os = new ObjectStructure();
2 os.Attach(new ConcereteElementA());
3 os.Attach(new ConcereteElementB());
4
5 //create visitor objects
6 ConcereteVisitor1 v1 = new ConcereteVisitor1();
7 ConcereteVisitor2 v2 = new ConcereteVisitor2();
8
9 //accepting visitors
10 os.Accept(v1);
11 os.Accept(v2);
12
13 Console.ReadKey();
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6
using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6
using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6
using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6
using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Gof.Test.Visitor
6
ObjectStructure os = new ObjectStructure();
2 os.Attach(new ConcereteElementA());
3 os.Attach(new ConcereteElementB());
4
5 //create visitor objects
6 ConcereteVisitor1 v1 = new ConcereteVisitor1();
7 ConcereteVisitor2 v2 = new ConcereteVisitor2();
8
9 //accepting visitors
10 os.Accept(v1);
11 os.Accept(v2);
12
13 Console.ReadKey();
相关文章推荐
- 模板方法模式(Template Method)-定义一个操作中的算法的骨架,而将一些步骤延迟到子类中。模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。
- 定义一个“点”(Point)类用来表示三维空间中的点(有三个坐标)。要求如下: (1)可以生成具有特定坐标的点对象。 (2)提供可以设置三个坐标的方法。 (3)提供可以计算该“点”距原点距离平方的方法。 (4)编写主类程序验证。
- 6.5 定义一个日期类 Date,该类对象存放一个日期,可以提供的操作有: void GetDate(); //取日期值,格式如“2001 年 2 月 5 日” void GetYear(); //取
- //6.5 定义一个日期类 Date,该类对象存放一个日期,可以提供的操作有: //void GetDate(); //取日期值,格式如“2001 年 2 月 5 日” //void GetYear(
- 定义一个日期Date,该类对象存放一个日期,可以提供的操作有:void :printDate(); //显示日期,格式如“日期是:2010年6月8日”void
- 不会改变操作对象内容的STL算法(元素查找,序列查找,统计元素个数,比较区间,找最值)
- for循环一个list,元素赋值给另一个对象,修改另一个对象,竟然可以修改list
- 定义一个交通工具(Vehicle)的类,在测试类Vehicle中的main()中实例化一个交通工具对象,通过方法给它初始化speed,size的值,并打印出来。另外,调用加速,减速的方法对速度进行改变
- 定义一个交通工具(Vehicle)的类,在测试类Vehicle中的main()中实例化一个交通工具对象,通过方法给它初始化speed,size的值,并打印出来。另外,调用加速,减速的方法对速度进行改变
- 使用了 :before 等伪元素中的其中一个来做 animation 动画; 在 animation 动画改变了其中的某个 rem 的值; 在这样的前提下,又是使用有这个 bug 的版本浏览器,那么就
- JS如何封装一些列方法为一个对象的操作,然后集中管理这些操作,方便修改和调用
- ios 中调用函数的方法是消息传递,这个和普通的函数调用的区别是,你可以随时对一个对象传递任何消息,而不需要在编译的时候声明这些方法。所以Objective-C可以在runtime的时候
- 当一个对象实例作为一个参数被传递到方法中时,参数的值就是对该对象的引用。对象的内容可以在被调用的方法中改变,但对象的引用是永远不会改变的.
- bo2-1.cpp 顺序表示的线性表(存储结构由c2-1.h定义)的基本操作(12个)
- 设定义一个类 整型数组的大小,表示可放元素的个数整型数组当前的元素个数,初始应为0,当elem等于size时,数组满
- 定义一个交通工具(Vehicle)的类,在测试类Vehicle中的main()中实例化一个交通工具对象,通过方法给它初始化speed,size的值,并打印出来。另外,调用加速,减速的方法对速度进行改变
- 定义一个交通工具(Vehicle)的类,在测试类Vehicle中的main()中实例化一个交通工具对象,通过方法给它初始化speed,size的值,并打印出来。另外,调用加速,减速的方法对速度进行改变
- const定义的对象属性是否可以改变
- 在Sprite 基础之上创建一个既可以控制移动,也可以动画的对象定义。
- 二叉树的树状数组和双向列表有区别,一个是针对明显的树状结构,一个是可以用来表示树状结构,Uva122