Sunday, August 31, 2008

Order of execution for class Constructor and Initializers

Hi All,

The origin of this post is the query posted at MSDN blog

This was a featured article at Start Page of VS2008 as well.

Well in short this is about that why Constructors of Base class are invoked first where as Initialization of class member variables is performed in Reverse Order i.e. from Derived to Base.

Until now we were suggested to save paper but now i believe in saving server hard disk as well :) So in case if you are interested to know the answer which i provided then please see search "Atreya A" at the original MSDN blog

namaste!

Wednesday, August 27, 2008

UML - Types of Relationships

1. Association

a. Aggregation: ‘has-a’ relationship: Employee has an address.
b. Composition: ‘part-of’ relationship: Engine is a part of Car

2. Inheritance: ‘type-of’ relationship : Car is a type of Vehicle
3. Realization: Implementation of some Interface

NOTE: Aggregation and Composition are sometimes confusing E.g. in examples above I have used car and engine in Composition Relationship, whereas Car and engine can also share an Aggregation as shown below:

“Swift Car has a Fiat Engine”

But the v.v.imp point here is that when we say that “Swift Car has a Fiat Engine”, the lifetime of object Fiat engine is not in hands of particular instance of ‘Swift Car’ because there might be some other car for which we can say that “Suzuki Sx4 has a Fiat Engine as well”
So the crux is that engine is a generic term here as there could be more than 1 owner/consumer
Whereas at the same time in a Composition Relationship there can’t be more than 1 owner at the same time i.e. 1 particular engine could be part of 1 car only. So if we destroy car object we can easily destroy the said instance of Engine object.