Reuse in todays world.

February 4, 2011

Imagine a world without factories (ok ok the greenies – like me – might see this in quite a positive light); that is a world without automation, without standards, without reusable components.  A world where everything is hand made.  Again, hand made is often perceived as a very good thing – albeit expensive – but many products in todays world are much better made in a factory – on an assembly line (ideally by tools/robots not people) where people of course (not machines!) designed the whole process.  Cheaper, more consistent and higher quality than hand made.

Well, in the world of software development, we are in the dark ages.  Everything is hand made, but with fantastic power tools.  We have not adopted the factory pattern [yet].  But you know, thinking clearly about this – we have so much more to gain than manufacturing by adopting the assembly line approach: first, we consume no raw materials; I can conjure up as many 1’s & 0′ in fancy patterns as I need for free.  Next, we have polymorphism; imagine we have designed an assembly line for 2 slice toasters and someone needs a 4 slice version.  We have lots of short panels – we retool to make longer panels, make many of those and assemble them on a modified assembly line.   In software, I inherit a 4 slice toaster side panel from a 2-slice toaster side panel in 1 line of code and adjust the size.   Virtually free.  I inherit all the goodness of the 2-slice panel but modify or tweak something.  Note: a lot of careful design has gone into the breakdown of the components – dont immediately get upset because your first effort at reuse in a similar way ended in disaster.

OK, now what?  I have all these components, how do I assemble them ad run them?   First, lets look at the evolution of the components.  They probably look like numbers, strings dates etc and various combinations of these.  But wait!  These are classes – they can have methods as well as data.  So now we have numbers, strings and dates on steroids.  And all polymorphic.  I can inherit an email address Type from string, or a phone number Type.  Maybe a dollar value from number, or a percentage.  Now any time I need one, I just pull it out from the toolkit.

“Pull it out of the toolkit”?  I suppose that means I model something with it.  Imagination time again; those that are not dreamers or dont know the TLAs of DSL and MDA can skip this bit.  Imagine a world where DSLs are mainstream – you may invent a language to suit your needs at any time.  Only proviso – it needs to be built upon the foundation Types from above (which include booleans, blobs and all known Types) and coded – once in a language.  Oh, and it needs to be documented, in a manner that a modelling tool understands to that the modelling process implicitly can speak the DSL.  Have you got the picture?  I am in a new domain, I invent a new language (in object.method notation of course) and I can model in that language.  Wouldnt that be cool!  And finally, having described both the Types/DSL in the modeller, and the application using that DSL, is it a big ask to be able to execute this application (remember above we had to code our DSL as well as document it).

Whats this blog all about?  Reuse.  So now the full circle: remember the core Types – number, string, date etc – they are reused across all of your applications!  Think about it for a while – that’s basically the promise of th OO panacea of the 90’s, albeit a few years late.

Now back to that lovely wild green happy planet with no factories…

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 )

Google photo

You are commenting using your Google 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

%d bloggers like this: