Understanding the need of Visitor Pattern
The of pattern need Understanding
2023-09-11 14:14:17 时间
Understanding the need of Visitor Pattern
The visitor pattern is a solution to a more general design problem:
I have a hierarchy of different classes. Each class supports various common operations. We would now like to extend that hierarchy, without having to change the existing hierarchy (e.g. because it is defined by a library we do not have the source code to).
- We can add more classes, which must support all required operations.
- We can add more operations, which must be supported by all classes in the hierarchy.
When designing a hierarchy, we can choose which of the two extension directions we want to make easy. (Trying to do both is called the Expression Problem and is extremely tricky.)
Since this is a bit theoretic, let's use an example – various kinds of animals. Each animal has a name()
and makes a sound()
.
相关文章
- PRVF-5436 : The NTP daemon running on one or more nodes lacks the slewing option "-x"
- Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
- On the usage of Google Analytics: are you violating the GDPR?
- The fileSyncDll.ps1 is not digitally signed. You cannot run this script on the current system.
- Inversion of Control Containers and the Dependency Injection pattern
- 报错:The specified datastore driver ("com.mysql.jdbc.Driver") was not found in the CLASSPATH. Please check your CLASSPATH specification, and the name of the driver.
- PHP Record the number of login users
- 视图控制器生命周期中各个重要的方法(Swift) (Important Methods during the Lifecycle of a View Controller)
- android常见错误-The container 'Android Dependencies' references non existing library
- 继承“HibernateDaoSupport”后,报“The hierarchy of the type AccoutDaoImpl is inconsistent”的解决方案
- Bad file format reading the append only file: make a backup of your AOF file, then use ./redis-check-aof --fix <filename>
- the server responded with a status of 414 (Request-URI Too Large)
- 程序员2020年新书推荐之 《Coders: The Making of a New Tribe and the Remaking of the World》
- The Pros and Cons of Using Third-Party APIs
- suseoj The wheat of the prime minister
- the resource is not on the build path of a java project错误
- 《Involution:Inverting the Inherence of Convolution for Visual Recognition》论文笔记