KEMBAR78
Object Oriented Program | PDF
Concept of C++
Paradigms – Paradigms means organizing
 principle of a program. It is an approach
                to a program.
Types of programming:-
 Procedural programming
 Modular Programming
 Object Oriented programming
Procedural programming lays more emphasis on
                procedure than data.
   Problems raised while extending the
  software or maintaining software by using
  procedural programming:-
 It is susceptible to design changes.
 It leads to increased time and cost overheads
  during design changes.
Module- A set of related procedure with
  data they manipulate is called a module.
In Modular Programming, since many modules (
  or functions) access the same data, the way the
  data is stored becomes critical. The arrangement
  of the data can’t be changed without modifying
  all the functions that access it.
The Object Oriented approach views a
 problem in terms of objects involved
  rather than procedure for doing it.
OBJECT ORIENTED
                                     PROCEDURAL PLANNING
        PROGRAMMING

   Here emphasis is an            Here emphasis is on
    object.                         doing functions.
                                   It follows Top-down
   It follows Bottom-Up            approach in program
    approach in program             design.
    design.                        Here presence of Global
                                    variables increase
   Its data hiding feature         changes of accidental
    prevents accidental             change in data.
    change in data.                Features like
   Its features like data          encapsulation, data
    encapsulation,                  hiding, polymorphism
    polymorphism, inheritance       are absent.
    are present.
Objects are key to understanding object-oriented
  technology. An object stores its state in fields
  (variables in some programming languages)
    and exposes its behavior through methods
 (functions in some programming languages).
Methods operate on an object's internal state and
  serve as the primary mechanism for object-to-
              object communication.
A class is a group of objects that share common
          properties and relationships.
class class-name{
                        private:
                          [variable declaration;]
                          [function declaration;]
                        protected :
                          [variable declaration;]
                          [function declaration;]
                        public :
                          [variable declaration;]
                          [function declaration;]
                    }
 Data Abstraction
 Data Encapsulation
     Modularity
    Inheritance
   Polymorphism
 Data abstraction refers to the act of
  representing essential features without
  including the background details or
  explanations.
 Data abstraction is the concept of
  simplifying a real world concept into
  essentials elements
The wrapping up of data and operations/functions
 (that operate on the data) into a single unit (called
          class) is known as encapsulation.

                            DATA

            OBJECT         MEMBER          OBJECT
                          FUNCTIONS


            DATA                              DATA

           MEMBER                           MEMBER
          FUNCTIONS        OBJECT          FUNCTIONS
Data modularity is the property of a system that
 has been decomposed into a set of cohesive and
           loosely coupled modules.
It is the capability of one class of things to
inherit capabilities or properties from other
                      class.
                       CLASS




       BASE                          DERIVED
       CLASS                          CLASS
Single Inheritance
 Multiple Inheritance
Hierarchical Inheritance
Multilevel Inheritance
  Hybrid Inheritance
In this type of inheritance a sub class inherits
            only from one base class.

                          x         BASE CLASS




                          Y         DERIVED
                                    CLASS
class Sub : public Super    //public derivation
{
    :                          //members of Sub
                               //(the derived class)
};
Class Sub : private Super   //private derivation
{
     :                         //members of Sub
};
class Sub : protected Super   //protected
                              //derivation
{
              :               //members of Sub
};
class Sub : Super             //private derivation
     by default
{
              :
};
In this type of heritance a sub class inherits
          from multiple base classes.
                    BASE CLASSES


        x                             Y
                       Z
                      DERIVED
                       CLASS
Class Sub : public SuperA,private SuperB
{

             :             //members

};
In this type of inheritance many sub classes
        inherit from a single base class.


                        Z             BASE
                                      CLASS




         W              X                Y
                    DERIVED CLASSES
                    DERIVED CLASSES
The transitive nature of inheritance is reflected by
 this form of inheritance . In this form a class that
          itself inherits from another class.

                             X        BASE CLASS OF Y




                             Y        DERIVED CLASS OF X
                                      BASE CLASS OF Z




                             Z         DERIVED CLASS OF Y
Hybrid inheritance combines two or more
           forms of inheritance.
 EXAMPLE
                          X

                Y                Z

           A          B          C
Polymorphism is the visibility for a
  message or data to be processed in more
              than one form .
It is a property by which the same message
  can be sent to objects of several different
   classes and each object can respond in a
     different way depending on its class .
void prnsqr (into i)
{ cout<<“Integer”<<i<<“ „s square is”<<i*i<<endl;
}
void prnsqr(char c);
{ cout<<c<<“is character”;
 cout<<“Thus No square for it”<<endl;
}
void prnsqr(float f)
{ cout<<“Double float”<<f<<“ „s square is”<<f*f;
  cout<<endl;
}
void prnsqr(double d)
{ cout <<“Double float”<<d<<“ „s square is”<<d*d<<endl;
}
Re – use of code
Ease of comprehension
Ease of fabrication and maintenance
Easy redesign and extension
 With OOP, classes tend be overly generalized.
 The relations among classes become artificial at
  times.
 The OOP programs design is tricky.
 Also one needs to do proper planning and proper
  design for OOP programming.
 To program with OOP, programmer need proper
  skills such as design skills, programming skills, etc.
Object Oriented Program

Object Oriented Program

  • 1.
  • 3.
    Paradigms – Paradigmsmeans organizing principle of a program. It is an approach to a program. Types of programming:-  Procedural programming  Modular Programming  Object Oriented programming
  • 4.
    Procedural programming laysmore emphasis on procedure than data. Problems raised while extending the software or maintaining software by using procedural programming:-  It is susceptible to design changes.  It leads to increased time and cost overheads during design changes.
  • 5.
    Module- A setof related procedure with data they manipulate is called a module. In Modular Programming, since many modules ( or functions) access the same data, the way the data is stored becomes critical. The arrangement of the data can’t be changed without modifying all the functions that access it.
  • 6.
    The Object Orientedapproach views a problem in terms of objects involved rather than procedure for doing it.
  • 7.
    OBJECT ORIENTED PROCEDURAL PLANNING PROGRAMMING  Here emphasis is an  Here emphasis is on object. doing functions.  It follows Top-down  It follows Bottom-Up approach in program approach in program design. design.  Here presence of Global variables increase  Its data hiding feature changes of accidental prevents accidental change in data. change in data.  Features like  Its features like data encapsulation, data encapsulation, hiding, polymorphism polymorphism, inheritance are absent. are present.
  • 9.
    Objects are keyto understanding object-oriented technology. An object stores its state in fields (variables in some programming languages) and exposes its behavior through methods (functions in some programming languages). Methods operate on an object's internal state and serve as the primary mechanism for object-to- object communication.
  • 10.
    A class isa group of objects that share common properties and relationships.
  • 11.
    class class-name{ private: [variable declaration;] [function declaration;] protected : [variable declaration;] [function declaration;] public : [variable declaration;] [function declaration;] }
  • 12.
     Data Abstraction Data Encapsulation  Modularity  Inheritance  Polymorphism
  • 13.
     Data abstractionrefers to the act of representing essential features without including the background details or explanations.  Data abstraction is the concept of simplifying a real world concept into essentials elements
  • 14.
    The wrapping upof data and operations/functions (that operate on the data) into a single unit (called class) is known as encapsulation. DATA OBJECT MEMBER OBJECT FUNCTIONS DATA DATA MEMBER MEMBER FUNCTIONS OBJECT FUNCTIONS
  • 15.
    Data modularity isthe property of a system that has been decomposed into a set of cohesive and loosely coupled modules.
  • 16.
    It is thecapability of one class of things to inherit capabilities or properties from other class. CLASS BASE DERIVED CLASS CLASS
  • 17.
    Single Inheritance MultipleInheritance Hierarchical Inheritance Multilevel Inheritance Hybrid Inheritance
  • 18.
    In this typeof inheritance a sub class inherits only from one base class. x BASE CLASS Y DERIVED CLASS
  • 19.
    class Sub :public Super //public derivation { : //members of Sub //(the derived class) }; Class Sub : private Super //private derivation { : //members of Sub };
  • 20.
    class Sub :protected Super //protected //derivation { : //members of Sub }; class Sub : Super //private derivation by default { : };
  • 21.
    In this typeof heritance a sub class inherits from multiple base classes. BASE CLASSES x Y Z DERIVED CLASS
  • 22.
    Class Sub :public SuperA,private SuperB { : //members };
  • 23.
    In this typeof inheritance many sub classes inherit from a single base class. Z BASE CLASS W X Y DERIVED CLASSES DERIVED CLASSES
  • 24.
    The transitive natureof inheritance is reflected by this form of inheritance . In this form a class that itself inherits from another class. X BASE CLASS OF Y Y DERIVED CLASS OF X BASE CLASS OF Z Z DERIVED CLASS OF Y
  • 25.
    Hybrid inheritance combinestwo or more forms of inheritance. EXAMPLE X Y Z A B C
  • 26.
    Polymorphism is thevisibility for a message or data to be processed in more than one form . It is a property by which the same message can be sent to objects of several different classes and each object can respond in a different way depending on its class .
  • 27.
    void prnsqr (intoi) { cout<<“Integer”<<i<<“ „s square is”<<i*i<<endl; } void prnsqr(char c); { cout<<c<<“is character”; cout<<“Thus No square for it”<<endl; } void prnsqr(float f) { cout<<“Double float”<<f<<“ „s square is”<<f*f; cout<<endl; } void prnsqr(double d) { cout <<“Double float”<<d<<“ „s square is”<<d*d<<endl; }
  • 28.
    Re – useof code Ease of comprehension Ease of fabrication and maintenance Easy redesign and extension
  • 30.
     With OOP,classes tend be overly generalized.  The relations among classes become artificial at times.  The OOP programs design is tricky.  Also one needs to do proper planning and proper design for OOP programming.  To program with OOP, programmer need proper skills such as design skills, programming skills, etc.