在软件构建过程中,由于需求的变化,某些类层次常常需要新增加新的行为,如果直接改变基类的方法的话,将给子类的维护带来巨大的灾难。解决的思路是使用visitor模式,需要新增加方法的类是不需要改动的,只要实现相应的接口即可。这里是英文解释:

Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates. 

实现代码:

相关文章:

  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-10-01
  • 2021-05-22
  • 2022-12-23
猜你喜欢
  • 2021-08-24
  • 2022-01-14
  • 2022-03-01
  • 2021-07-21
  • 2021-05-17
  • 2021-05-18
相关资源
相似解决方案