While writing the code I stumbled upon one weird architecture problem.
Let's presume we need some functionality in the form of a class hierarchy. We want this functionality to replaceable. For example due to platform change. The question is what is the proper way to organize this?
So far, this is what I came to:
This hierarchy is what client uses (at least should) no matter what platfrom is underneath.
Then presume two cases:
In both cases implementation should easily be switched.
And on this point my confusion begins. How to achieve this? I though of the Bridge and Adapter patterns. Bridge is the closer thing what maybe can work. However classic bridge only contains pointer to implementation base class and we have hierarchy wich adds new methods/data, so we can't just use base interface of the implementation. (although we can try to substitute implementation in the derived class, but it's no longer a classic bridge).
Adapter also seems does not work with hierarhies.
If all the above doesn't make sence, consider two examples.
1. We have texture hierarchy:
-----------Texture2d
/
BaseTexture-----------Texture3d
\
----------CubeTexture
We want this to be implemented in OpenGL or DirectX. We don't have an implementation and will provide it ourselves.
2. We have XML hierarchy
-------XmlDocument
/
XmlNodeBase-------XmlElement
Now we have the library which implements the functionality for us and we just want to abstract away the libarary hierarchy in a sebsible way. (i.e. these 3 classes are our iterfaces and we have similar hierarchy in the library and we need to 'put' lib classes into our hierarchy preserving relationships in a cross-platform way)
Remember derived classes extend the interface! So we can just throw in the abstract factory and be happy, because it only works if the interface is the same and implementation differs.
Again, the only thing I came to is to modify bridge pattern. Any ideas or comments that you have? This seems like usual taks for the cross-platform game engine, because there are many modules which should be relpaced for different platforms.
Let's presume we need some functionality in the form of a class hierarchy. We want this functionality to replaceable. For example due to platform change. The question is what is the proper way to organize this?
So far, this is what I came to:
This hierarchy is what client uses (at least should) no matter what platfrom is underneath.
Then presume two cases:
- We already have the implementation of the functionality for the given platform
- We will implement this functionality ourselves
In both cases implementation should easily be switched.
And on this point my confusion begins. How to achieve this? I though of the Bridge and Adapter patterns. Bridge is the closer thing what maybe can work. However classic bridge only contains pointer to implementation base class and we have hierarchy wich adds new methods/data, so we can't just use base interface of the implementation. (although we can try to substitute implementation in the derived class, but it's no longer a classic bridge).
Adapter also seems does not work with hierarhies.
If all the above doesn't make sence, consider two examples.
1. We have texture hierarchy:
-----------Texture2d
/
BaseTexture-----------Texture3d
\
----------CubeTexture
We want this to be implemented in OpenGL or DirectX. We don't have an implementation and will provide it ourselves.
2. We have XML hierarchy
-------XmlDocument
/
XmlNodeBase-------XmlElement
Now we have the library which implements the functionality for us and we just want to abstract away the libarary hierarchy in a sebsible way. (i.e. these 3 classes are our iterfaces and we have similar hierarchy in the library and we need to 'put' lib classes into our hierarchy preserving relationships in a cross-platform way)
Remember derived classes extend the interface! So we can just throw in the abstract factory and be happy, because it only works if the interface is the same and implementation differs.
Again, the only thing I came to is to modify bridge pattern. Any ideas or comments that you have? This seems like usual taks for the cross-platform game engine, because there are many modules which should be relpaced for different platforms.
Looking for a job!
My LinkedIn Profile
My LinkedIn Profile
The post was edited 2 times, last by devast3d ().