object oriented concepts through c++

Upload: prasanthrajs

Post on 03-Jun-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Object Oriented Concepts through C++

    1/3

    Ammas

    C++ - A Revisiting

    C++ is Object Oriented Programming Language Its application domains include systems software,application software,device drivers, embedded

    software, high-performance server and client applications, and entertainment software such asvideo

    games.

    Procedure-Oriented Programming

    o In this approach, the problem is viewed as a sequence of things to be done such as reading,calculating and printing. A number of functions are written to accomplish these tasks.

    o The primary focus is on functions.o Very little attention is given to the data that are being used by various functions.o For large program it is very difficult to identify what data is used by which function.o E.g. of languages which follow this is approach : COBOL, FORTRAN and C

    Characteristics of Procedure-Oriented Programming:

    o Importance is on doing things(algorithms)o Large programs are divided into smaller programs known asfunctionso Employs top-downapproach in program designo Functions share global data

    Object-Oriented Programmingo Def: It s an approach that provides a way of modularizing programs by creating partitioned

    memory area for both data and functions that can be used as templates for creating copies

    of such modules on demand. (Object is considered to be partitioned area of computer

    memory)

    o It ties data more closely to the functions that operate on it and protect from unauthenticmodifications by outside functions.

    o Decomposition of problem into a number of entities called Objects.Characteristics of Object-Oriented Programming:

    o Importance is on data rather than procedure.o Programs are divided into what are known as objects.o Data is hidden and cannot be accessed by external functionso Employees bottom-upapproach in program design.

    Basic Concepts of OBJECT- ORIENTED PROGRAMMING Object

    o It is a real world entity. ( basic run-time entity)o It may represent a person, student, a bank account etco Classes define types of data structures and the functions that operate on those data

    structures. Instances of these data types are known asobjects and can contain

    member variables, constants,member functions

    Classeso Its a user defined data typeo The entire set of data and code of an object can be made a user-defined data type with

    the help of class.

    http://en.wikipedia.org/wiki/Application_softwarehttp://en.wikipedia.org/wiki/Video_gameshttp://en.wikipedia.org/wiki/Video_gameshttp://en.wikipedia.org/wiki/Object_%28computer_science%29http://en.wikipedia.org/wiki/Variable_%28programming%29http://en.wikipedia.org/wiki/Method_%28computer_science%29http://en.wikipedia.org/wiki/Method_%28computer_science%29http://en.wikipedia.org/wiki/Method_%28computer_science%29http://en.wikipedia.org/wiki/Variable_%28programming%29http://en.wikipedia.org/wiki/Variable_%28programming%29http://en.wikipedia.org/wiki/Object_%28computer_science%29http://en.wikipedia.org/wiki/Video_gameshttp://en.wikipedia.org/wiki/Video_gameshttp://en.wikipedia.org/wiki/Application_software
  • 8/12/2019 Object Oriented Concepts through C++

    2/3

    Data Encapsulationo The wrapping up of data and function into a single unit (called class) is known as

    encapsulation. Data and encapsulation is the most striking feature of a class.

    o Data is accessible through member functions in the class and does not provide directaccess to the data from the outside world. This insulation of the data from direct access

    by the program is called data hiding or information hiding.

    o Real world example of data encapsulation:A car consists of wheels, steering, engine, etc. but together it is considered as a one unit

    called Car.

    Data Abstractiono Abstraction refers to the act of representing essential features without including the

    background details or explanation.

    o Real world example :When a person is pressing on the switch, the light gets ON but the he is unaware of the

    phenomenon that takes place at the background. (i.e. showing essential features without

    representing background actions)

    Inheritanceo Inheritance is the process by which objects of one class acquired the properties of objects

    of another classes.

    o This provides the idea of reusability. This is possible by deriving a new class from theexisting one

    o Real world example :

    Properties of an object of a class Human will be acquired by object of classes like Student, Teacher and

    Farmer. Each class gets properties of its parent class Human and also includes its own properties.

    Polymorphism

    o Polymorphism means ability to take more than one form, i.e. an operation can exhibitdifferent behaviour at different instance depend upon the data passed in the operation

    the real life example

    o Real world example :Some water purifiers can produce the pure water in hot, cold and normal form.

    The form of the water produced is determined by the option selected by the

    user. (i.e. Same machine but different behaviours on different inputs) .

  • 8/12/2019 Object Oriented Concepts through C++

    3/3

    Two types :

    Compile time polymorphismEg:

    Operator overloading

    The process of making an operator to exhibit different behaviors in

    different instances is known as operator overloading.

    Function overloading

    Using a single function name to perform different type of task is known as

    function overloading.

    Run PolymorphismEg: Virtual Functions.

    Dynamic BindingDynamic binding means that the code associated with a given procedure call is not known until

    the time of the call at run time.

    Message PassingObjects communicate with one another by sending and receiving information

    1. Object-based programming languageso Supports encapsulation and object identity.

    Major feature that are required for object based programming are:

    Data encapsulation

    Data hiding and access mechanisms

    Automatic initialization and clear-up of objects

    Operator overloading

    o They do not support inheri tance and dynamic binding.o Adais a typical object-based programming language.

    2. Object-oriented programming languageo It incorporates all of object-based programming features along with two additional features, namely,

    inheritance and dynamic binding.

    Object-based features + inheritance + dynamic binding