OOps Concepts

1.  Why OOP?

Suppose that you want to assemble your own PC, you go to a

hardware store and pick up a motherboard, a processor, some RAMs,

a hard disk, a casing, a power supply, and put them together. 

You turn on the power, and the PC runs.  You need not worry

whether the motherboard is a 4-layer or 6-layer board,

whether the hard disk has 4 or 6 plates; 3 inches or 5 inches in diameter,

whether the RAM is made in Japan or Korea, and so on.

You simply put the hardware   components   together

and expect the machine to run.  Of course, you have to make sure that

you have the correct interfaces, i.e., you pick an IDE hard disk

rather than a SCSI hard disk, if your motherboard supports only IDE;

you have to select RAMs with the correct speed rating, and so on. 

Nevertheless, it is not difficult to set up a machine from hardware components.

Similarly, a car is assembled from parts and components,

such as chassis, doors, engine, wheels, break, transmission, etc.

The components are reusable, e.g., a wheel can be

used in many cars (of the same specifications).

Hardware, such as computers and cars, are assembled from parts,

which are reusable components.

How about software?  Can you “assemble” a software application

by picking a routine here, a routine there, and expect the program to run?

  The answer is obviously no!  Unlike hardware,

it is very difficult to “assemble” an application from software components

Since the advent of computer 60 years ago, we have written

tons and tons of programs.  However, for each new application,

we have to re-invent the wheels and write the program from scratch.

Why re-invent the wheels?

1.1  Traditional Procedural-Oriented languages

OOP_CFunction

Can we do this in traditional
procedural-oriented programming

language such as C, Fortran, Cobol, or Pascal?

 

Traditional
procedural-oriented languages (such as C and Pascal)

suffer some notable
drawbacks in creating reusable software components:

The programs are made up of functions.
Functions  are  often   not 
reusable.    

It   is very difficult to copy a function
from one program and reuse in another program because the the

function is likely to reference the headers,
global variables and other functions.
In other words, functions are not well-encapsulated
as a self-contained 
reusable unit.

2.The procedural  languages
are  not  suitable  of  
high-level abstraction
 for  solving  real  life  problems. For example,
C programs uses constructs such as if-else, for-loop, array, function, pointer,
which are low-level and hard to abstract real problems such as a
Customer Relationship Management (CRM) system or a computer soccer game.
(Imagine using assembly codes, which is a very low level code, to write a computer soccer game. C is better but no much better.)

In brief,
the traditional procedural-languages
separate the data structures and algorithms of the software entities.

  • In the early 1970s,
    the US Department of Defense (DoD) commissioned
  • a task force to investigate why its IT budget always went out of control;
  • but without much to show for. The findings are:
  • The task force proposed to make software behave
  • like hardware OBJECT. Subsequently,
  • DoD replaces over 450 computer languages,
  • which were then used to build DoD systems,
  • with an object-oriented language called Ada
  • 80% of the budget went to the software (while the remaining 20% to the hardware).
  • More than 80% of the software budget
  • went to maintenance (only the remaining 20% for new software development).
  • Hardware components could be applied to various products,
  • and their integrity normally did not affect other products.
  • (Hardware can share and reuse! Hardware faults are isolated!)
  • Software procedures were often non-sharable and not reusable.
  • Software faults could affect other programs running in computers.

1.2  Object-OrientedProgramming Languages

OOP_Objects

Object-oriented programming (OOP) languages are designed to overcome these problems.

  1. The basic unit of OOP is a class, which encapsulates both the static attributes and dynamic behaviors within a “box”, and specifies the public interface for using these boxes. Since the class is well-encapsulated (compared with the function), it is easier to reuse these classes. In other words, OOP combines the data structures and algorithms of a software entity inside the same box.

  2. OOP languages permit   higher   level   of   abstraction   for   solving  real-life   problems.   The traditional procedural  language (such as C and Pascal) forces you to  think  in  terms of  the  structure of  the computer (e.g. memory bits and bytes, array, decision, loop) rather than thinking in terms of the problem you are trying to solve. The OOP languages (such as Java, C++, C#) let you think in the problem space, and use software objects to represent and abstract entities of the problem space to solve the problem.

OOP_SoccerGame

As an example, suppose you wish to write a computer soccer games (which I consider as a complex application). It is quite difficult to model the game in procedural-oriented languages. But using OOP languages, you can easily model the program accordingly to the “real things” appear in the soccer games.

  • Player: attributes include name, number, location in the field, and etc; operations include run, jump, kick-the-ball, and etc.

  • Ball:

  • Reference:

  • Field:

  • Audience:

  • Weather:

Most importantly, some of these classes (such as Ball and Audience) can be reused in another application, e.g., computer basketball game, with little or no modification.

1.3  Benefits of OOP

The procedural-oriented languages focus on procedures,

with function as the basic unit. You need to first figure out

all the functions and then think about how to represent data.

The object-oriented languages focus on components

that the user perceives, with objects as the basic unit.

You figure out all the objects by putting all the data and

operations that describe the user’s interaction with the data.

Object-Oriented technology has many benefits:

  • Ease in   software   design   as   you  could  think  in  the

  •   problem space rather  than  the machine’s  bits and bytes.

  • You are dealing with high-level concepts and abstractions.

  • Ease in design leads to more productive software development.

  • Ease in software maintenance: object-oriented software are easier to understand, therefore easier to test, debug, and maintain.

  • Reusable software: you don’t need to keep re-inventing the wheels and re-write the same functions for different situations.

  • The fastest and safest way of developing a new application

  • is to reuse existing codes – fully tested and proven codes.

Procedure-Oriented Programming :—–

       High level language such as  C,  forton is  commonly knowns as procedural languages..

Some characteristics of this language:—>

c-2

Emphasis is on doing things(algo)

Large programms are divided into smaller programms knowns as functions

most of functions share global data.

Data moved openly around the system from function to function

Employs Top to down approach in program design.

Object Oriented Programming Programming :————

Some characteristics of this language:—>

c-1

Emphasis is on data rather than procedure.

Programms are divied into what are known as objects

Data structure are design such that they characterize the objects

Function that operate on the data of an object are tied together in the data structure

Data is hidden and can not be accessed by external functions

Objects communicate with each other  through functions

New data can be easily added when needed

Follow Bottom to up approach in programs.

Basic concepts of object-oriented  programming

1.objects ( O ) 

2.classes ( C)

3.Data abstractions and encapsulation  (D)

4.inheritance  ( I )

5.Polymorphism ( P )

6.Dynamic binding ( D )

7.Message passing( M )

you can remember  using code —–OCD- IPDM—–

1. Objects   :–

 it contains data and code  to manipulate data..  objects interact with each other by sending messages.. they  have memory address.. it is userdefined data type

it may represent

a person

a place

any item

2. classes :- –     Each object is associated with the data of type class with which they are created .. A

class  is collection of objects of similar type.

int i  — here int is a class we can create several objects of that class..  int indicate kind of data .  object tell that what kind of operation can be  performed on it.

example :  — mango, apple, orange are members of the class fruit.

it is also userdefined data types.

Difference between  objects and class  :-

A  class is a design. Object  is the creation from  this  design.

Multiple objects can be  c-3created from a single class. the class defines the type of objects that can be created   according   to  the  data the object  can  hold  and  operations the object     can         perform.

3 . 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 such as size , weight, and cost and functions   to operate on these attributes.

The    wrapping  up  of  data functions    into  single  unit  is  known  as     Encapsulation.         

 The data is not accessible to the outside world and  only  those function which are wrapped in the class can access it. these function provides the interface between the object’s data and

the program. The insulation    of the   data    from

direct    access     by   the  program is called    Data hiding   or   information hiding.

4 . Inheritance :–   A process by which objects of one class acquire the properties of objects of another class.

supports the concepts of hierarchical classification.

 In oops the concept of inheritance provides the idea of reusability. this means that we can add additional features to an existing class without modifying it. this is possible by deriving a new class from the existing one.

Subclass defines only those features which are unique to it. it includes its features explicitly.

c-4

5 . Polymorphism : —      Polymorphism allows objects

having different internal structures

to share the same external interface.

Polymorphism is extensively used in implementing inheritance.

We can say the ability to assume  several forms. the ability of entity to refer to objects of various classes at runtime.

C++ has three machanisms that help us to implement polymorphism

! .Function Overloadingc-5

2. Operator Overloading

3.Virtual functions

6.Dynamic Binding :

Binding refers to the linking of a procedure call to the code to be executed in response to call.  Dynamic binding means(late binding)

also means that the code associated with a given procedure is not known untill the time of the call at run time. it is associated with polymorphism and inheritance

you can understand this from above example by inheritance every object will have draw procedure  but its definition is unique to each class so this procedure is redefined in each class that defines the  object. the matching code is called at run time.

7. Message Passing :  

 in object oriented program consist of a set objects that communicate with each other.

they involves following steps.

     1. create the class that defines objects and their behaviour

    2.  Create objects from that class

   3. Establishing communication among objects.

c-6

What is difference between Object based language and object oriented language?

       object oriented is not the right of any particular language . OOP concepts can be implemented using languages such as C and pascal. but it may generate confusion when program become larger.

A language is specially designed to support  OOP concepts makes it easier to implement them

A language  will have to support severals of OOPs concepts to claim it is Object oriented.

 they can be classified in two ways:——–

1. Object based language

2. Object oriented language

features supported by Object based language :——–

                   1.Data encapsulation

                   2. Data hiding and access mechanisms

                   3. Automatic intialization and clear-up objects.

                   4. Operator overloading

They do not support Inheritance and Dynamic binding

Object oriented language  it supports all object based programming features along with two additional features

1. Inheritance

2. Dynamic binding

. Object oriented language            =      Object based features + inheritance   +    dynamic binding

like –  c++ and java

Applications of OOP :——-

                                           Object oriented databases

                                           Real time systems

                                           Neural networks and parallel programming

                                           CIM/CAD    systems

https://csekapil.wordpress.com/2013/11/05/tree-learn-in-…for-interviews

https://csekapil.wordpress.com/2013/11/05/c-programms-as…ost-interviews/


Leave a comment