I had a problem increasing visitor patterns in many modules, you can read the explanation of the problem in the comments. Example of interface Interface (interface) (ISO server (Visitors);} class Module1Source1 applies ISource {@ override public objects accepted (ISourceVisitor visitor) {return visitor.visit (this) ;}} Class Module1Source2 applies ISource {@ override public objects accepted (ISourceVisitor visitor) {return visitor.visit (this);}} interface ISourceVisitor {object travel (Module1Source1 wheel); object travel (Module1Source2 engine);} class supported Christian Trivia Visitors iisoswiziter {@ Override Public Object Visit (Module 1 Source 1 Wheel) {Return Immutable List ("USD");} @OverWide Public Object Visit (Module 1 Source 2 Engine) {Return ImmutableList.of ("EUR") ; /> Suppose we do not want to change the above code because it is in any other library / I want to add another source class. Module2Source1 implies imers {@Override Public Objects Accept (ISourceVisitor visitor) {return null;}} // I can not change the ISourceVisitor, so what do I need to do? // One way is to create another interface interface IAnotherModuleSource ISource extension (Object accept (IThisModuleSourceVisitor visitor);} Interface ITIS module extends source visitor iSourceVisitor {Object Visit (Module 2 Sources 2 Module 2 Assus 2);} Class Module2Source2 implements iAnotherModuleSource {// It is ok @ Accept the override public object (IThisModuleSourceVisitor visitor) {return visitor.visit (this);} // But what do we do with it Want:? @ Override public object accept (return visitor) {return accepted (Visitors to ITIS module source visitor);} // In this way if supported curvature visitors will be sent to Module2Source2 then we will have // cce // But it is fine if we pass specific visitors for this module}} Obviously if we
the question is whether we can do better with the visitor Are you?
Or what Be programmed? Would you suggest in this situation?
TL; Dr.: The problem you are describing is a result of trying to apply the pattern of such a problem for which it is not conducive.
"Reasons to change" fall into all 2 basic categories: Data and functionality separates normal OO direct link between visitor pattern data and functionality, so that you are able to easily change the functionality In return, the ability to change the data structure can be abandoned. It would be trivial to add another ISourceVisitor because the visitor pattern is designed to do this. By connecting another > iisers , you can change your data structure and you can force it to change all your functionality to adjust, which is a definite sign that you have picked the wrong pattern.
Comments
Post a Comment