Bug Vanquisher

10 October 2009

The Composition Which Isn’t

Filed under: Dev inside!, Tips — Tanveer Badar @ 5:11 PM

Imagine someone trying to write a class which composes two streams together. You better make it a stream itself, meaning something like this:

class CompositeStream : IStream
    CompositeStream( IStream* first , IStream* second );
    // blah blah blah

Or people will find it amusing that your class isn’t a stream itself.

Similarly, for a mathematical library if you provide a composing function it better be a math-op itself or someone is going to end up in a sticky situation.

class SuperDuperComposingFunction : MathOp
    SuperDuperComposingFunction( const std::vector< MathOp* >& operations );
    // blah blah blah

Or a cache manager for that matter. It is easy to provide default implementations for simple cache algorithms like LFU, LRU, FIFO etc. But things get interesting if you provide an extensibility point for others to compose them together. Who knows whether I want to archive emails which are older than 3 weeks and I haven’t read them more than once. Things are even more interesting if people need to sub-class your cache manage in order to use composite cache policies.

In the end, it helps to read these things instead of arguing when someone says “yeah sure, great idea. Just one thing, make it a ICachePolicy itself.”.

This post was brought to you by “Working with goons”.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: