Object Oriented Programming
August 7, 2009
OBJECT ORIENTED PROGRAMMING
Object oriented programming (OOP) is introduced as a new programming concept which should help one in developing high quality software. Object-orientation is also introduced as a concept which makes developing of projects easier. Object oriented programming attempts to solve the problems with only one approach; dividing the problems in sub-modules and using different objects. Objects of the program interact by sending messages to each other.
Examples of object oriented languages are C++, Smalltalk (First Object Oriented Language), Simula (Pure Object Oriented Language), Java, C#.
OBJECT ORIENTED CONCEPTS
- Data Abstraction and Encapsulation
Objects are the basic run-time entities in an object-oriented system. Programming problem is analyzed in terms of objects and nature of communication between them. When a program is executed, objects interact with each other by sending messages. Different objects can also interact with each other without knowing the details of their data or code.
A class is a collection of objects of similar type. Once a class is defined, any number of objects can be created which belong to that class.
Data Abstraction and Encapsulation
Abstraction refers to the act of representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes. Storing data and functions in a single unit (class) is encapsulation. Data cannot be accessible to the outside world and only those functions which are stored in the class can access it.
Inheritance is the process by which objects can acquire the properties of objects of other class. In OOP, inheritance provides reusability, like, adding additional features to an existing class without modifying it. This is achieved by deriving a new class from the existing one. The new class will have combined features of both the classes.
Polymorphism means the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends on the data types used in the operation. Polymorphism is extensively used in implementing Inheritance.
Need For OOP
Decompose larger problem into smaller sub problems that can be solved separately.
Composability — Structured Design
We can easily combine modules to produce new systems.
Incremental development from small and simple to more complex modules.
Changes and maintenance in only a few modules does not affect the architecture.