The home of the haikulator

 

Links

My Stand-up & gigs
The Coding Craftsman
BurberryAndBroccoli
MarkInventions

The Musical!
Incredible Productions

apostrophell
backlash
incredible
haiku


Previous Posts

Quite Confusing
Watching In Slow Motion
How romantic
Some random advice for budding comedians
With Respect To Believers
I Should Bloody Know Better
Extremes of customer service
We have two cats
Ah, a spam message
Digital download is best!?

Blog Archives

January 1970
October 2001
November 2001
December 2001
January 2002
February 2002
March 2002
April 2002
May 2002
June 2002
July 2002
August 2002
September 2002
October 2002
November 2002
December 2002
January 2003
February 2003
March 2003
April 2003
May 2003
June 2003
July 2003
August 2003
September 2003
October 2003
November 2003
December 2003
January 2004
February 2004
March 2004
April 2004
May 2004
June 2004
July 2004
August 2004
September 2004
October 2004
November 2004
December 2004
January 2005
February 2005
March 2005
April 2005
May 2005
June 2005
July 2005
August 2005
September 2005
November 2005
December 2005
January 2006
February 2006
March 2006
April 2006
May 2006
June 2006
July 2006
August 2006
September 2006
October 2006
November 2006
December 2006
January 2007
February 2007
March 2007
April 2007
May 2007
June 2007
July 2007
August 2007
September 2007
October 2007
November 2007
December 2007
January 2008
February 2008
March 2008
April 2008
May 2008
June 2008
July 2008
August 2008
September 2008
October 2008
November 2008
December 2008
January 2009
March 2009
April 2009
May 2009
August 2009
September 2009
January 2010
March 2010
April 2010
May 2010
June 2010
July 2010
August 2010
September 2010
October 2010
November 2010
December 2010
January 2011
February 2011
March 2011
April 2011
May 2011
June 2011
July 2011
August 2011
October 2011
December 2011
February 2012
March 2012
April 2012
May 2012
June 2012
July 2012
March 2013
April 2013
May 2013
June 2013
July 2013
August 2013
September 2013
October 2013
December 2013
January 2014
February 2014
March 2014
May 2014
July 2014
January 2015
February 2015
March 2015
April 2015
May 2015
June 2015
July 2015
August 2015
January 2016
February 2016
March 2016
April 2016
May 2016
July 2016

Global Domination

Locations of visitors to this page

Friday, April 1

Hammer Job, Job Hammer

Note: this is a geeky coding post, so please stop reading unless you care about this sort of thing.

I remember my own mistakes of the past. I used to use one trick with object oriented programming (still reading?). I used to use inheritance. There were a lot of reasons for this, and I blame Microsoft - not in a "Windows is shit" kind of a way, but more because they made a lot of use of inheritance in examples and automatically generated code, so it became the common tool for any job.

When you have a hammer, everything's a nail, right?

Well, time's moved on for me, and I've learned of two other techniques:
  • HAS-A - sometimes you can use an instance of another object to DO what you want, rather than have everything become something else, just to use some behaviour
  • State vs type - it's not necessary to provide the answer to certain parameters by overriding the getters for that data, you can just store the data in the object which needs to be configured.

There are more techniques, of course... but these two are the ones which seem to be forgotten. If everything has to be a type, then you end up with types that basically provide static data via dynamic getters, which could be replaced by having the data stored in the object and used with static getters.

Mind you, there are reasons when you want to do things the opposite way around. If you're using patterns where there are tons of objects, and you want them to be virtually stateless, then the type can dictate the notional state, since a single type identifier can imply a lot of data.

Let's not even mention the Liskov substitution principle. Ok. Let's mention it. A is set to be of type B, if you can use A in any place where you can use a B. This defines inheritance, but kind of assumes that you haven't made A undo some of B's behaviour. So if B always does a thing, and A makes it not happen, then you've got something which defies the idea of additive inheritance. It's sometimes a necessary evil.

Right now, I've got some classes on my screen where there's a template, which has all manner of possible data items. Somehow, rather than implementing a single type where these items can be easily turned on and off, the implementing person has created a type for each possible permutation, which duplicate bits of each other. In this situation, there's a single type and just variants of how to configure it... multiple types don't help.

Ockham's razor, in Latin, reads - Pluralitas non est ponenda sine neccesitate, or Entities should not be multiplied unnecessarily. So today's job is having fewer duplications, entities, types and nails being hit by hideous hammers.

2 Comments:

Blogger Steve said...

And let's not even talk about multiple inheritance, which my hazy memory tells me you were a huge fan of... :-)

6:12 PM  
Blogger Ashley Frieze said...

Why not do it in style!?

I could probably justify that design choice in a job interview situation, but I'm not sure I'd do it that way if I had my time over.

A beer and a whiteboard discussion, methinks.

12:58 AM  

Post a Comment

<< Home

All content ©2001 - 2012 Ashley Frieze