Saturday, February 6, 2010

nth maximum value from table

select Max(empage) from Emp
where empage not in (select top 1 empage from Emp  order by EmpAge desc )

Friday, February 5, 2010

abstraction and encapsulation

abstraction

abstraction is a process. It manages complexity of objects. Abstraction identifies critical behavior of objects and eliminates the tedious details.

Example: i need to create a payroll software and software should have details of all employees within company. Employees behaviors will differ from one another. Different employees will have different hobbies, different size and shape, etc. All these behaviors are not required for creating payroll software. So we should follow a process for identifying crucial behaviors of the object. In case of payroll system, employee object should have employee id, name, band and department. All other behaviors can be eliminated. This process is called abstraction.


encapsulation

encapsulation is the mechanism by which abstraction can be implemented. Storing data and function in a single unit(class) is encapsulation. data's cannot be accessible from the outside world. function within classes can access these data. This is often referred as Information hiding.


Example: Consider a Math class. It has Add method and other member variables. Add method is exposed to the outside world. But outside world will not be knowing what is happening inside Add method. This is called information hiding.


reference:

http://oreilly.com/catalog/objectvbnet/chapter/ch01.pdf

Association, Aggregation, Composition



I have a hand, I have a car.

I have a hand - life time of hand is same as my life time. hand dies with me :) it is tightly coupled. Its composition

I have a car - my car remains even if  I die. This is aggregation.

association: is a relationship between two classes. It is the basic way of relation between two classes.

aggregation and association are more specific way of relationship between classes.

aggregation: has a relationship. one class can exist without other class
composition: one class is tightly coupled with other class. Life time of the classes will be the same.





Example2:


university has a chancellor   (association)
university have faculties  (composition)


university can exist without chancellors
university cannot exist without faculties. if faculties dispose then university will not exist.

university composed of faculties