Wednesday, March 26, 2008

OOP Concept

Object-Oriented programming..
* Procedural programming involves viewing a computer program as a sequential list of computational steps / procedures) to be carried out. In procedural programming, the list of procedures can be further broken down into subroutines and functions.
* Object Oriented Programming in any language is the use of objects to represent functional parts of an application and real life entities. For example you may have a Person object to hold the data related to a person and even provide some functionality that this person may be capable of.
* The term Object that gives OOP it’s name, refers to a conceptual object that represents an item / entity in system.
* attributes - the characteristics of our object.
* methods - a set of functions and calculations that are either performed to modify the object itself, or are involved in some external effect.
* The constructor of a class is a special operation that is run upon instantiation - when an object is created. It cannot have a return type. A properly written constructor should never contain any functionality that could fail, thus leaving the object in an invalid state.
* The destructor of a class is the opposite of the constructor in that it is run when an object is destroyed. It’s function is to clean up and to free the resources which were used by the object during run-time and unlink it from other objects or resources. This should result in the invalidation of any references in the process.

OOP language should have:
* Inheritance
* Polymorphism
* Encapsulation, Abstract data types and information hiding

=> Inheritance : Inheritance allows a (sub)class to inherit all the attributes and methods of a parent class - in effect, extending the parent. It can best be described as an “is a” relationship. For instance, if we had a class of “fruit”, we could extend it by defining classes of “apple”, “orange” and “banana” (apple "is a" fruit)
* Composition is a slightly different sort of relationship - this is where it could be said that a class was “composed” of other classes. For instance, a wall is “composed” of bricks and a molecule is “composed” of atoms. Neither of these examples could be described as inheritance - the statement, “a wall is a brick” simply isn’t true. Composition can be described as “has a” and “uses a” relationships; a wall “has a” brick or a wall “uses a” brick.
* The main difference between two relationships association & aggregation is simple; in association the composing classes are destroyed when the parent is destroyed, however, in aggregation they are not. This ultimately means that, when aggregation is adopted as a relationship, the composing classes and objects can be re-used in other classes and objects within the system.

=> Polymorphism : meaning different classes can have different behaviours for the same attribute or method. Overloading is a good example of polymorphism in action. Polymorphism, at it’s most basic, describes the fact that a given function may have different specifications, depending on the object to which it is applied.
* Late Binding :

=> Encapsulation, Abstract data types and information hiding :

No comments: