How to solve cyclic dependencies in a visitor pattern
Posted
by
Benjamin Rogge
on Programmers
See other posts from Programmers
or by Benjamin Rogge
Published on 2012-10-31T09:09:26Z
Indexed on
2012/10/31
11:13 UTC
Read the original article
Hit count: 254
When programming at work we now and then face a problem with visitors and module/project dependencies.
Say you have a class A in a module X. And there are subclasses B and C in module Y. That means that module Y is dependent on module X. If we want to implement a visitor pattern to the class hierarchy, thus introducing an interface with the handle Operations and an abstract accept method in A, we get a dependency from module Y to module X, which we cannot allow for architectural reasons.
What we do is, use a direct comparison of the types (i.e. instanceof
, since we program in Java), which is not satisfying.
My question(s) would be: Do you encounter this kind of problem in your daily work (or do we make poor architectural choices) and if so, how is your approach to solve this?
© Programmers or respective owner