Oops Basics
Oops Basics
Content :
• This has forced the software engineers and industry to continuously look for new
approaches to software design and development, and they are becoming more and
more critical in view of the increasing complexity of software systems as well as
the highly competitive nature of the industry.
• These rapid advances appear to have created a situation of crisis within the
industry.
• The following issued need to be addressed to face the crisis:
• How to represent real-life entities of problems in system design?
• How to design system with open interfaces?
• How to ensure reusability and extensibility of modules?
• How to develop modules that are tolerant of any changes in future?
• How to improve software productivity and decrease software cost?
• How to improve the quality of software?
• How to manage time schedules?
Software Evolution
• Ernest Tello, A well known writer in the field of artificial intelligence, compared the
evolution of software technology to the growth of the tree.
• Like a tree, the software evolution has had distinct phases “layers” of growth. These layers
were building up one by one over the last five decades as shown in fig. 1.1, with each layer
representing and improvement over the previous one.
• With the advent of languages such as c, structured programming became very
popular and was the main technique of the 1980’s.
• Structured programming was a powerful tool that enabled programmers to write
moderately complex programs fairly easily.
• However, as the programs grew larger, even the structured approach failed to
show the desired result in terms of bug-free, easy-to- maintain, and reusable
programs.
• Another serious drawback with the procedural approach is that we do not model
real world problems very well.
• This is because functions are action-oriented and do not really corresponding to
the element of the problem.
• Don’t have any proper way to hide the data, so it is less secure
Object Oriented Programming
• OOP is introduced in order to overcome the flaws in procedural and traditional approach
to programming as they were lacking in
• Reusability of code
• Maintainability of code
• Fundamental idea behind object-oriented language is to combine both data and the
functions that operate on that data into a single unit.
• Such a unit is called an object.
•
• The process of programming in an object-oriented language, involves
the following basic steps:
1. Objects
2. Classes
3. Data abstraction
4. Data encapsulation
5. Inheritance
6. Polymorphism
7. Dynamic binding
8. Message passing
Objects
• Objects are the basic run time entities in an object-oriented system.
• They may represent a person, a place, a bank account, a table of data or any item that the
program has to handle.
• They may also represent user-defined data such as vectors, time and lists.
• Programming problem is analyzed in term of objects and the nature of communication
between them.
• Program objects should be chosen such that they match closely with the real-world objects.
Classes
• A class is a collection of objects of similar types.
• The entire set of data and code of an object can be made a user-defined data type with the
help of class.
• Once a class has been defined, we can create any number of objects belonging to that class.
• Syntax for creating object of the class is:
class-name object-name ;
• For examples, Mango, Apple and orange members of class fruit.
• If fruit has been defined as a class, then the statement
Fruit Mango;
Will create an object mango belonging to the class fruit.
Data Encapsulation
• The wrapping up of data members (variables) and member functions (methods) into a single unit
(called class) is known as encapsulation.
• Data encapsulation is the first principle of object oriented programming.
• The data is not accessible to the outside world, and only those functions which are wrapped in
the class can access it.
• These functions provide the interface between the object’s data and the program.
• Encapsulation means hiding the important features of a class which is not been needed to be
exposed outside of a class and exposing only necessary things of a class.
• The process of deriving a new class from the existing one is called inheritance. The new
class will have the combined feature of both the classes.
• The old class is known as base class or the parent class while the new class is known as
derived class or sub class.
• For example, the bird,
‘robin’ is a part of class
‘flying bird’ which is
again a part of the class
‘bird’. The principal
behind this sort of
division is that each
derived class shares
common characteristics
with the class from
which it is derived as
illustrated in fig 1.6.
• Inheritance is the most powerful feature of oop and provides the idea of
reusability, which in turn will increase the quality of work and
productivity.
• For two numbers, the operation ‘+’ will generate a sum of two numbers and if the
operands are strings, then the operation ‘+’ would produce a third string by concatenation.
• The process of making an operator to exhibit different behaviors in different instances is
known as operator overloading.
Dynamic Binding (Late Binding)
• Binding refers to the link between function call and code to be execute (function
definition).
• It is the process of linking of a function call to the actual code of the function.
• Dynamic Binding: When binding takes place at the run time.
• In Dynamic binding, the actual code to be executed is not known to the compiler
until run-time.
• For example:
Function call:
func();
func(a);
Function definition:
Void func() {cout<<“hello”;}
Void func(int a) {cout<<a;}
Message Passing
• Objects are made to communicate or interact with each other with the help of a
mechanism called message passing.
• Objects can send or receive message or information.
Object based languages supports the usage of object Object Oriented Languages supports all the features
and encapsulation. They does not support inheritance of Oops including inheritance and polymorphism.
or, polymorphism or, both.
Object based languages does not supports built-in They support built-in objects.
objects.
JavaScript, VB are the examples of object based C++, C#, Java, VB. Net are the examples of object
languages. oriented languages.