The future of software is… Back to the basics
George Malamidis, September 10th, 2006A little bit more than a couple of years ago Component Oriented Design was all the rage. Beyond Object Oriented Programming they said… For about a month.
The fine print, of course, mentioned that Components were not there to replace OOP, more like complement it.
I guess the books didn’t sell very well and as a result you hardly ever hear anyone mentioning Components these days.
Truth of the matter is, Components have always been there as an integral ingredient of OO. Because, if we ignore the attributes that were attached to them a few years ago to feed book pages (call me Web Services, Distributed, etc), a Component is essentially a bunch of Classes collaborating inside their little cosmos and communicating with the rest of the world through a narrow interface.
In its simplest form, say, a Java component, is some code in a package.
Writing a component is easy, provided we keep one simple rule in mind. The world is oblivious to what happens inside the component. The world is only interested in what the component can provide it with and what the component needs to perform its task. In other words, the world should only care calling the methods of a Component’s public Interface.
‘All this sounds so simple and basic and everybody knows about it since school…’ I can imagine you saying and a fair claim it is.
So why doesn’t anyone do it?
Blame whoever you want, but today’s Java development has reached a point where access levels, packages and interfaces have completely lost their meaning.
Here’s a few rules of thumb you might want to consider for designing more effectively:
Start by giving every new Class package level access instead of making it public. Same goes for non-private methods.
Don’t give private methods default access just to unit test them. Use reflection instead.
Do not give every class an Interface. Contrary to popular belief, Interfaces are not there to accommodate auto-wired Dependency Injection.
Create packages based on their Domain identity, not their type of functionality. For example, do com.universe.solarsystem.services and com.universe.solarsystem.dao instead of com.universe.services.solarsystem and com.universe.dao.solarsystem.
Treat packages (Components) they same way you treat classes. Decompose them based on responsibilities and make them remember to tell, don’t ask.
There’s an ancient OO paradigm called Encapsulation and it goes beyond Classes. Hide your Component’s internals and only expose what’s needed. Collaborators don’t care how the Component performs its magic.
In the vast majority of cases, it makes more sense to make code specific, instead of generic. Think of the small picture, then the bigger picture and then fit those in the Big Picture.
Get the basics right before you leverage the framework. And choose frameworks in a way that will suit your design instead of basing your design on Frameworks.

September 11th, 2006 at 11:01 am
One of the reasons why OOP is disappearing is becuase of lot of frameworks which may not really be OO and also perhaps the reason for non maintainable code..
September 11th, 2006 at 1:43 pm
there was an interesting thread on the exposure of methods/classes/interfaces in the Yahoo XP group a few months back, http://tech.groups.yahoo.com/group/extremeprogramming/message/120709.
It was a longish running discussion about the benefits of exposing a restricted API that makes it easier to understand the intention of the designer in making the code versus the benefits of exposing more of the code to allow people to do things that may not have been envisioned by the original author(s).
One of the interesting ideas I took from it was you could use namespaces/packaging to seperate narrow easy to understand APIs while exposing a larger API, which may be of interest to users of the code for ideas other than those originally envisioned by the author.
September 12th, 2006 at 8:31 pm
Another concept to remember is that a component should be completely self contained and deployable on it’s own. That doesn’t mean you can’t deploy it along with other components/application, but that you could if you wanted to. A component should not depend on anything but itself as far as deploying it is concerned. Any other “things” that it needs to do it’s job should also be components and “talked” to thru interfaces.
December 1st, 2006 at 1:26 am
This is a good article.
OO is not going away; what is going away is the attention of a large number of fairly new programmers to the basics, as this article tries to emphasise.
Before OO, there was structured, and before that, modular prorgamming.
But the fundamental principles go to the very first assembly language macros and routines:
encapsulate, encapsulate, encapsulate