Wednesday, August 19, 2009

c++: Polymor--virtual, overload, inheritance..

Encapsulation

Encapsulation is grouping data and functions together and keeping their implementation details private. Greatly restricting access to functions and data reduces coupling, which increases the ability to create large programs.

Classes also encourage coherence, which means that a given class does one thing. By increasing coherence, a program becomes easier to understand, more simply organized, and this better organization is reflected in a further reduction in coupling.
Inheritance

Inheritance means that a new class can be defined in terms of an existing class. There are three common terminologies for the new class: the derived class, the child class, or the subclass. The original class is the base class, the parent class, or the superclass. The new child class inherits all capabilities of the parent class and adds its own fields and methods. Altho inheritance is very important, especially in many libraries, is often not used in an application.
Polymorphism

Polymorphism is the ability of different functions to be invoked with the same name. There are two forms.

Static polymorphism is the common case of overriding a function by providing additional definitions with different numbers or types of parameters. The compiler matches the parameter list to the appropriate function.

Dynamic polymorphism is much different and relies on parent classes to define virtual functions which child classes may redefine. When this virtual member function is called for an object of the parent class, the execution dynamically chooses the appropriate function to call - the parent function if the object really is the parent type, or the child function if the object really is the child type. This explanation is too brief to be usesful without an example, but that will have to be written latter.

No comments:

Post a Comment