Wednesday, July 09, 2008

Dependency Injection: Simple Complexity (Part I)


Uhm... I don't know why some geniuses amongst us like to make life simply complex for some of us. It is has been really hectic figuring out the core meanings and interpretation of hypothesis in this domain we found ourselves - Software Solution Development Domain.

It is almost becoming a strength-test terrain, where only the strong survives. Without the extra gut to ask the extra HOW & WHY, in fact, one might be frustrated in no time at all to join Nollywood and do the do like they do. Apology to my powerful artists.

I have been hearing about some very bogus terms for some times now. The "bigness" of these words scared me and i dared not examine what their concoction really meant. I was trapped in this locker until I came across someone who resounded them - "Dependency Injection / Inversion Of Control". What tha hell? I thought.

Imagine the freedom of a baby wandering in a lion's den without the awareness of the danger looming ahead. That was the feeling I got from this newbie. He was just reading everything and implementing all. He thought I would be a good lead. he rushed to be when he was flogged. Exactly thesame way that baby would run for help sighting the lion in its den.

But really, this lion could have been a screensaver, to the beautiful world behind it. Just a simply complex way to infiltrate spoilers. And sometimes it could be real - DANGER. In whatever way, how do you find out?

Get closer and probably, Touch!!!

I rushed back and in very simple terms these are my findings:

1: After runnig to dictionaries, Dependency mean "rely on", "need", "made up of". Grammarians, please help me out.

So in a programmic expression, dependency means that a class needs an object of another class in its creation. SIMPLY COMPLEX?

Example:
First discreet class Heart is defined as:


public class Heart
{
int beat = 0;

public int Beat
{
get{return beat;}
set{beat = value;}
}
}

Now, Learn dependency. lol:

public class Man
{
Heart heart = null;

public Man()
{
this.heart = new Heart();
}
}

You know what that means. No Heart, no Man. So you could say that Man depends on Heart. SIMPLY SIMPLE.


Moving further, Injection. What does it mean? By the dictionaries also, Injection could mean "Introduce", "put into", "put in a place" and the list could grow.

Programically speaking, it means that you can, using the above example, give a potentially Heart-broken Man a Heart. Lover boys, come along.

Example:

public class Man
{
.
.
.
public Man(Heart heart)
{
//use heart up here
}
}

We have succeeded in injecting a heart into a Man without one. lol.

This is not the limits of what you could do with DI. When you exhaust this, we'll move on up like Access bank.

Now tell me what you don't know about DI. Martin Fowler has only tried to bamboozle our minds with some big grammars. It is a only a way to advertise a 5cents product using a 5million dollar TV station platform. But think about 5million of 5cent. That is where the complexity sets in

Think about it