Reputation: 81
I've got four similar class structures that are generated from XSDs, each one is a different version of an API.
The thing is, I have classes that operate on all these different class structures, but a good deal of the code is the same throughout all structures. I can't have interfaces for each class since all classes are generated from XSDs. Yet I want to remove duplication from my codebase...
What would be a good OO solution here?
Thanks.
Upvotes: 1
Views: 180
Reputation: 1026
I'd probably go for using a facade class. This class is your one point that needs to know about the other four classes. It deals with relaying calls to the correct class. This way you not only achieve the reduction of duplicate code, but you also abstract the API's from the rest of your codebase, making it easier to deal with changes in the API's.
HTH.
Upvotes: 0
Reputation: 78282
I would use a little object composition. Define a class that holds the shared functionality and keep an instance as a member for each of your generated classes. Try to minimize the amount of mutable state you keep in the class so you can test it easier.
Upvotes: 0