Thursday, January 21, 2010

OOPS

Object:

An object is merely a collection of related information and functionality.

Inheritance

First, inheritance is an example of what’s known in object-oriented design as an “is-a” relationship. 

Composition 

Composition gives us a 'part-of' relationship.
Within composition, the lifetime of the part (Engine) is managed by the whole (Car), in other words, when Car is destroyed, Engine is destroyed along with it.





Aggregation

Aggregation gives us a 'has-a' relationship. Within aggregation, the lifetime of the part is not managed by the whole.


Polymorphism

An abstract class, which is a class that defines the functions a derived class must implement and that sometimes provides functions that are useful to both classes.

Abstract functions are automatically virtual functions, which allow the programmer to use polymorphism to make their code simpler. When there’s a virtual function, the programmer can pass around a reference to the abstract class rather than the derived class, and the compiler will write code to call the appropriate version of the function at runtime.

Polymorphism and virtual functions are used in many places in the .NET runtime system. For example, the base object object has a virtual function called ToString() that’s used to convert an object into a string representation of the object. If you call the ToString() function on an object that doesn’t have its own version of ToString(), the version of the ToString() function that’s part of the object class will be called, which simply returns the name of the
class. If you overload—write your own version of—the ToString() function, that one will be called instead, and you can do something more meaningful, such as writing out the name of the employee contained in the employee object.

Encapsulation

Overloading


Sometimes it may be useful to have two functions that do the same thing but take different parameters. This is especially common for constructors, when there may be several ways to create a new instance.


Virtual


Virtual means that when a call to a member function is made, the compiler should look at the real type of the object (not just the type of the reference) and call the appropriate function based on that type.


Sealed classes prevent a class from being used as a base class. They’re primarily useful to prevent unintended derivation.A sealed method lets a class override a virtual function and prevents a derived class from
overriding that same function.

Static Constructor will be called before the first instance of an object is created. It’s useful to do setup work that needs to be done only once.





No comments: