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










Thursday, January 28, 2010

Why name JIT?

.net compiler convert source code into intermediate language during compilation. this is also called as Microsoft intermediate language(MSIL).
Its the job of the JIT compiler to take MSIL and convert it to native code at run time.


.net will not convert all MSIL code into native code at once. Because it is time and space consuming. Some part of the .net code never executes. So there is no need to keep this code in the memory. This is resource consuming.


So .net came up with an approach called JIT compilation, it converts MSIL to native code on demand at application runtime. So the name JUST IN TIME COMPILING

Wednesday, January 6, 2010

Measuring execution time in C#

How to measure a method's execution time without using timer?

Use DateTime and TimeSpan classes in .net framework.

public void sampleMethod()
{
DateTime starttime = DateTime.Now;
//
//......
//do code here
//......
DateTime endtime = DateTime.Now;
TimeSpan duration = endtime - starttime;
string time = duration.Hours + ":" + duration.Minutes + ":" + duration.Seconds + ":" + duration.Milliseconds;
}

Wednesday, December 16, 2009

How much unit test coverage you need?

Not less than 80% of coverage is advisable.

Effective test should consider not only code, but also input parameters, and application state which could also affect the behavior.

  1. test success condition
  2. test failure condition
  3. test boundary condition

http://www.codeproject.com/KB/testing/UnitTestVS2008.aspx

    Wednesday, December 2, 2009

    Sealed

    • It restricts inheritance
    • Cannot derive from Sealed type