I have a Channel with some properties and a ChannelProxy extending Channel. This ChannelProxy holds the original values so that Optimistic Concurrency can be applied. You can switch between no concurrency check and Optimistic Concurrency check.
Now I want to implement a LazyLoadedChannel which can be a Channel or a ChannelProxy. Extending both is not possible. What’s a good solution for this kind of problem?
I could create a LazyLoadedChannel (extending Channel) and a LazyLoadedChannelProxy (extending ChannelProxy), but that means that code will be duplicated in both classes.
Decorator Patterns sounds a good choice to me as well.
As an alternative, however, you could do this:
Channelconfigurable as lazy loaded or non-lazy-loaded. You could use a Strategy Pattern to achieve this.Channelis configurable thusly,ChannelProxy, since it is only a subclass, should be automatically configurable too. So you may not have to do anything more.ChannelProxymay have to provide its ownLoadingStrategyclass.