I have been looking for this pattern for some time but still did not get very good way of representing this .
Consider a GUI design which needs to show attributes of an object based on version , these versions specify which attributes makes sense to a client . (say the client has details of supported versions )
The GUI layout need to change based on the version of this object . For example for certain versions we want to show additional menus etc. For some we want to change the ordering of the attributes etc.
For the above condition is there any pattern which defines how to represent the classes ?
Currently the way we do is to have a check for versioning for these but its getting out of control , so i am looking for a solution which allows us to share the common code and also keep the version specific code separate so that we can maintain it . And changes to a version localized .
I would extract shared functionality out into another object and have them composed inside your actual class.
For example, if the class is A, you would do CommonA and have A_1 contain an object of CommonA and A_2 contain an object of CommonA as well. Here A_1 and A_2 represent version 1 and version 2.
Both A_1 and A_2 expose the same methods and internally delegate to the shared class.
This way you are not duplicating and you localize your version specific stuff inside each of A_1, A_2 etc.