Monthly Archives: November 2013

So SOLID Crew

Have you ever gone shopping and come home with too many bags, only for one of the handles to snap, leaving you with all your stuff in a mess on the floor. Notice how it’s always the bags with the eggs in it?

Well, just as you can get overwhelmed if you’re trying to do too many things at the same time, so can your code. If you don’t want to end up with egg on your face as a developer, it’s best to make sure your classes and method have only one responsibility.

Open Closed Principle

Imagine a world without letterboxes. Imagine a time when you had to leave your front door wide open just in case the post man wanted to deliver a letter. Anyone could come inside, make a mess of your front room, break things and leave! Not good.

Luckily, we don’t live in that sort of a world. If someone wants to send you a letter then the message is posted through your letterbox, then you can read it and choose to respond to the letter without allowing anyone to into your home.

Liskov Substitution Principle

It’s summer time and the garden is looking a little bit neglected. It’s time to do a bit of gardening and add a border to the lawn but we’re much too clever to do all the hard work ourselves, not when we have RoboSlave ready, willing and waiting for our every command.

We’re going to need some seeds, some compost and a spade to dig out the border so we send RoboSlave on his merry way to a DIY store to pick up the things we need.

Interface Segregation Principle

The idea behind Interface segregation principle is that big isn’t always better. Sometimes a small, perfectly formed interface offering only one or two methods is better than a large interface that forces anyone creating a derived type to implement lots of methods, even if they’ll only ever want to use a small subset of that functionality.

Dependency Inversion Principle

In recent years Apple started a trend of phones with concealed built-in batteries that couldn’t be replaced by users and other phone manufactures have since followed.

They will tell you that they did this because they wanted their casing to be made of one single piece of aluminium, that it looked beautiful and saved weight but in my opinion it was a cynical ploy to force you into a dependency on Apple.

If there was a problem with your battery, you have to take the phone back to Apple for repair. You can’t buy a cheaper after-market alternative battery without voiding your warranty. Battery performance degrades over time so in doing this, they’d effectively created a need for you to buy a new phone every couple of years.