Search This Blog

Thursday, 13 October 2011

Object Oriented Methodology

0 comments
Object Oriented Methodology

OO languages combine both data and functions, the core elements of a program into a single entity called object. Objects allow localization of data and code and restrict other objects from referring to their local region.
OOP treats data as the critical element in a program and does not allow the data to flow freely around the system. It ties the data more closely to the functions that operate on them and protects them from accidental modifications from other parts of the program.
The protected data can be freely accessed only from the functions that are associated with them. However, the functions of one object can access the functions of another object. The following are some of the striking features of OOP:
  1. Emphasis is on data rather than procedure.
  2. Programs are divided into what are known as objects.
  3. Date and functions that operate on data are tied together into an entity called object.
  4. Data are hidden within the object and can’t be directly accessed by external functions.
  5. New data and functions can be easily added whenever necessary and
  6. Follows bottom-up approach in program design.
The organization of data and functions in object-oriented programs is shown in the following figure:

Fig. : Organization of data and functions in OOP


Consider an object - account with three attributes: AccountNumber, AccountType, Name and Balance, and three operations: Deposit, Withdraw, and Enquire. The pictorial notation of this object is shown in the below figure:

Fig. : Different styles of representing the object - Account
In C++, objects are coded using a programming element called class. The following code illustrates this:
class account {
private:
char Name[20];
char AccountType;
long int AccountName;
float Balance;
public:
void Deposit();
void Withdraw();
void Enquire();
}
In this example, class is a keyword which indicates the beginning of a new class. The word account is the name of the class. The body of the class containing details about the data and functions of the account object and is enclosed with in a pair of curly braces.
The main advantage of using OO approach is reusability. Through this mechanism, an object already written can be reused to minimize the time and effort required to rewrite similar kind of objects. When a new object requires similar set of functionalities of an existing object and some additional features, instead of designing it from scratch, we can derive (create) it from an existing one.

Leave a Reply