S h o r t S t o r i e s

// Tales from software development

Abstract class or interface ?

leave a comment »

While adding some new functionality to a tracing and logging library I couldn’t decide whether I needed a new interface or a new abstract base class to implement a new feature.

I started with an abstract base class but changed my mind and used an interface instead. Then I changed my mind again when I realised that I needed the class constructors to be part of the contract.

There are times when it’s obvious that an interface definition is needed and similarly there are times when it’s obvious that a base class is the solution. But in situations where it’s not obvious, for example the implementation of internal code in an assembly, then deciding whether constructors are part of the implementaion contract may guide you to the answer.

Advertisements

Written by Sea Monkey

September 20, 2011 at 8:00 pm

Posted in Development

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: