Reputation: 25949
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.
Upvotes: 0
Views: 132
Reputation: 36818
Decorator Patterns sounds a good choice to me as well.
As an alternative, however, you could do this:
Channel
configurable as lazy loaded or non-lazy-loaded. You could use a Strategy Pattern to achieve this. Channel
is configurable thusly, ChannelProxy
, since it is only a subclass, should be automatically configurable too. So you may not have to do anything more. ChannelProxy
may have to provide its own LoadingStrategy
class.Upvotes: 2
Reputation: 4665
As said above (Dmitri) it looks like a decorator that you put over your channel. Assuming that your Proxy accesses the values only if needed - i.e. when they're about to be changed.
Upvotes: 0