I have a class ABC that can do operation a(), b() and c() (operation == method), which are all closely related. I also have simimar classes DE and FGH. In the future, it is possible new classes are added with additional operations. Classes never share operations (for example, there is no class ADF)
My program should be able to perform all these operations, and the timing is "kind of random", meaning I have no estimate beforehand of which operation will be executed when/how many times.
I tackled this program by creating a wrapper class "OperationInvoker". My program can only access this invoker, and it has one method for each operation. The advantage of this is encapsulation: if new operations are created or existing one or edited, onlt the wrapper class needs editing.
My question is whether a "huge" wrapper is the best pattern to solve this?
I looked into the observer pattern for this by I think this is not a suitable case because the classes ABC, DE, FGH ... never have any mutual interests. Like, if operation A needs to be executed, all registered classes will receive event A and only 1 class (namely, ABC) will be actually interested in this event. all other registered classes will discard the event. This seems like overkill/overhead with all the registering and observing.
The delegation pattern also suffers the same problem: i don't have many classes doing the same operation in a different way, so there is no point in having a flexible delegation system.
Are there other, better patterns, or is this just a simple case of having a delegating wrapper class?
EDIT: someone asked what exactly ABC does. Well, I have a WSDL file that describes SOAP web services. I use a tool to convert this file to java classes. This means I cannot control the content of these classes as they are auto generated. So I wrote a class WebServiceInvoker which acts as a wrapper around these web services. This wrapper class has 3 methods: do web service A, do web service B, and do web service C.
As the program expands, more and more wsdl files enter the picture. Of course none of the web services do the same thing. The only reason why they are not all bundled together in one big wsdl file is because some web services just don't belong logically next to other web services. So I wind up with the following classes:
- A wrapper class which can call web service A, B and C
- A wrapper class which can call web service D, E
- A wrapper class which can call webservice F, G and H
It is possible in the future more wsdl's (and thus wrapper classes) appear. The reason why is there an additional wrapper around all the other wrappers is because every service needs to be called with a "session id". So every wrapper needs to know this information. So the superwrapper holds this information, and can call all web services. This also works very well as an api: the program who uses the web services knows nothing of the services, it just has 1 public method available for each web service through the superwrapper. The program of course is aware of what each web service returns (a list, a string, nothing...).