You are on page 1of 4

Why do we need OOP?

Object oriented programming was developed because limitations were discovered in earlier approaches to programming. Some of these limitations were: 1234A program in procedural language is a list of instructions. This is not practical when program becomes larger. In a program in a structured language functions have unrestricted access to global data. Data and functions are unrelated. Creation of new data types was not possible. People see the world in terms of objects. Accurate real world modeling in computer programs is not possible in procedural and structured programming approaches.

Object oriented approach tries to model the real world more accurately. It provided solutions and efficient techniques to overcome the limitation discovered in earlier programming paradigms.

History of Languages:
Monolithic: Early languages (1954-58) Only numeric data Processing Global Data Used to create simple applications, numeric computation. No subprograms Example: FORTRAN-1 Procedural Languages: In procedural language the programmer specifies explicit sequences of steps to follow to produce a result. Some properties of such languages are: Used for medium size application Sub programs are allowed Global variables No data hiding Examples: FORTRAN-2, COBOL

Structured Languages: A structured language is a programming language that follows a methodology where the logic of a program is a structure composed of similar sub-structures in a limited number of ways. Structured programming usually involves a procedural language, rather that a linear language such as BASIC, although any programming language can be structured.

Local as well as global data Modular programming

Problems in structured languages: 1Functions have unrestricted access to global data 2Poor modeling or real world (data and functions are not related) 3Program structure difficult to conceptualize 4Difficult to modify

OBJECT ORIENTED APPROACH The fundamental idea behind object oriented language is to combine into a single unit both data and functions that operate on the data. Such a unit is called object. An object function is called member function or method. Typically provide the only way to access its data. To read a data item in an object, its member function is called. The data is hidden and cannot be accessed directly. Data and functions are said to be encapsulated in to a single entity. Data encapsulation and data hiding are the key terms in the description of object oriented languages.
Object

Data

Member functiuon Member functiuon

Object

Object
Data

Data

Member functiuon Member functiuon

Member functiuon Member functiuon

Program typically consists of a number of objects which communicate with each other by calling one anothers member functions.

Advantages of OOP:
People think in terms of objects OO model maps the reality and close to real world Easy to develop and easy to understand Information hiding

Object:
Object is any person, thing, idea or concept. Complex real world objects have both attributes and behavior. An object is usually denoted by a rectangle. An object has a unique identity. Examples of objects: Object Ali Car Time Attributes Name, Age, height Model, Color Hour, Minutes, Seconds Behavior Walk, eat Moves, turns Set Hour, Set Minute, Set Second

Information hiding
Information is stored in the object Can be manipulated by the object itself

Advantages: Simplify the model by hiding implementation details Its bars against changes and propagation No direct access

Encapsulation:
Coupling of data and behavior is called encapsulation. Advantages: Simplicity Clarity Less complexity

Interface
Objects communicate in OO through interface. Interface activates behaviors.

Classes
A class serves as a plan or template. It specifies what data and what functions will be included in the object of that class. Objects are members of classes. Inheritance Classes are divided into sub-classes. Each sub-class shares the common characteristics with the class from which it is derived. In addition, each class has its own characteristics.

In OOP classes can be derived into subclasses. Original class is called base class. Other classes can be defined that share its characteristics but add their own as well. These are called derived classes.

Reusability
Once classes has been written, created and debugged, it can be distributed to other programmers for use in their own programs.

Polymorphism
Polymorphism is the ability to use an operator or method in different ways. Polymorphism gives different meanings/functions to operators/methods. Types of polymorphism Operator overloading Function overloading Virtual function

You might also like