Acyclic visitor
暂无分享,去创建一个
Procedural software can be written in such a way that new functions can be added to existing data structures without affecting those data structures. Object oriented software can be written such that new data structures can be used by existing functions without affecting those functions. In this regard they are the inverse of each other. Adding new data types without affecting existing functions is at the heart of many of the benefits of OO. Yet there are times when we really want to add a new function to an existing set of classes without changing those classes. The V ISITOR 2 pattern provides a means to accomplish this goal. However, the V ISITOR pattern, when used in static languages like C++, Java, or Eiffel, causes a cycle in the source code dependency structure. (See Figure 1 and the legend at the end of this paper.) A source code dependency means that the source code of one module must refer to (via #include , or import , or some other mechanism) the source code of another module.