Lieven Cardoen
Lieven Cardoen

Reputation: 25949

Design Issue

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

Answers (3)

G S
G S

Reputation: 36818

Decorator Patterns sounds a good choice to me as well.

As an alternative, however, you could do this:

  1. Make your Channel configurable as lazy loaded or non-lazy-loaded. You could use a Strategy Pattern to achieve this.
  2. Once 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.
  3. Or : depending upon what 'loading' entails, ChannelProxy may have to provide its own LoadingStrategy class.

Upvotes: 2

Rashack
Rashack

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

Dmitry Ornatsky
Dmitry Ornatsky

Reputation: 2237

Looks like Decorator pattern is an option.

Upvotes: 2

Related Questions