Wednesday, February 02, 2011

Ditching Firefox

I have just decided to ditch Firefox in favor of Chrome. This is because Firefox 3.6.13 was very unstable. Every time I used to start, it used to crash. I then upgraded to Firefox 4.0 Beta, but because it is beta, it is very sluggish. On firefox beta hotmail also didn’t work quite good. Hotmail not working is not firefox’s problem but I was getting victimised. Chrome sorts out all those problems and gives me feeling of being light and brisk.

Firefox will be the choice of browser only at work and that too only because of one add-in ”Firebug”. There is “firebug lite” for IE and Chrome, but it is not there yet. So firefox for work, chrome for all other personal stuff. Oh yeah, IE 9 beta is there on my home Windows 7. But that is just for fun!

Difference between Association, Aggregation and Composition

This has been a haunting question to me for some time. I had been trying to get a concrete understanding on differences among these three terms. If you google on differences among these three terms, you will get all sorts of explanation. I was tempted to link couple of those explanations here but that would have just increased their relevancy in google’s eyes (so I won’t do that).

If you google for Aggregation, you will find innumerous guys (in-fact Wikipedia) out there who would define aggregation for you like this:

Aggregation differs from ordinary composition in that it does not imply ownership. In composition, when the owning object is destroyed, so are the contained objects. In aggregation, this is not necessarily true. For example, a university owns various departments (e.g., chemistry), and each department has a number of professors. If the university closes, the departments will no longer exist, but the professors in those departments will continue to exist. Therefore, a University can be seen as a composition of departments, whereas departments have an aggregation of professors.

Isn’t this definition useless? If my cell phone “has a” camera, without cell phone this camera is useless on its own. Camera might be atomic unit on its own however without the parent object it does not reveal its behavior. People try to define this same scenario in other words that camera continues to have its existence and might be fully functional within another cell phone. This is where I have problem. I see this that once parent object is not in existence, contained object has lost its value.

Gang of Four in their book “Design Patterns Elements of Reusable Object Oriented” has handled it pretty good and in a clear way:

Aggregation implies that one object owns or is responsible for another object. Generally we speak of an object having or being part of another object. Aggregation implies that an aggregate object and its owner have identical lifetimes.

This is what we know as composition. They go further and try to define association:

Acquaintance implies that an object merely knows of another object. Sometimes acquaintance is called "association" or the "using" relationship. Acquainted objects may request operations of each other, but they aren't responsible for each other. Acquaintance is a weaker relationship than aggregation and suggests much looser coupling between objects.

This is fine. In association we are not talking about containing each other and controlling the life time. All we are doing is requesting the operations i.e File.IsExists or Path.Combine.

On Composition vs Aggregation, in his book “UML Distilled, third edition”, Martin Fowler says:

Composition is a good way of showing properties that own by value, properties to value objects, or properties that have a strong and somewhat exclusive ownership of particular other components. Aggregation is strictly meaningless; as a result, I recommend that you ignore it in your own diagrams.

And when Martin Fowler is discouraging us to use Aggregation, he meant messed up Aggregation.

Hence forward my stand on Aggregation and Composition will be the union of what GoF says and what Martin Fowler says. GoF calls Composition by the name of Aggregation, so I say that Aggregation and Composition are the same things where there is a “has a” relationship and lifetime is identical for Owner and contained object (Aggregator and Aggregatee). Going forward there are only two things for me, Association and Composition (which is also called Aggregation by GoF).