The fundamental of OOPs include –

Definition of OOPs

  • The term Object-Oriented Programming” (OOP) was coined by Alan Kay circa in 1966 or 1967 while he was at grad school.
  • Ivan Sutherland’s seminal Sketchpad application was an early inspiration for OOP.
  • It was created between 1961 and 1962 and published in his Sketchpad Thesis in 1963
  • Object-Oriented Programming (OOP) is a modern programming paradigm to solve complex problems.
  • The term OOP was used by ‘Xerox PARC’ for the first time in its programming language, called Smalltalk referring to the usage of objects as computational units for processing, in the mid-1960s.
  • The feature of inheritance was introduced for the first time in Smalltalk.
  • Simula was the first programming language developed in the mid-1960s to support the object-oriented programming paradigm followed by Smalltalk in the mid-1970s and is known to be the first ‘pure’ object-oriented language.
  • Eiffel, Java, C++, Object Pascal, Visual Basic, C# etc are the other OOP languages.

Feature of OOPs

There are following features of OOPs are described below – 

Class :

  • It is the building block of C++, Java, etc.
  • It is a user-defined data type, that holds its own data members(data variables/properties) and member functions(behavior), which can be accessed directly or indirectly by an object of the same or different class.
  • A class is a set of objects that shares a common definition described by data and methods.
  • A class is like a blueprint that represents a group of objects that share some common properties and behaviors.
  • A class contains data and functions/methods together in a bundle.
  • In other words, a class is a collection of similar types of objects.
  • A class is an object template.
  • A class is defined by the keyword class.
  • A class represents a set of objects that share a common structure and a common behavior.
  • Being part of the class, data, and function are called members of the class. The body of the class is enclosed within braces and terminated by the colon.
  • The keywords private, public, and protected are known as visibility labels, which define the visibility of members. It is common practice to declare data members as private and member functions as public.
  • The declaration of a class does not define any object but only specifies the structure of objects i.e. what they will contain.
  • A class must be instantiated (object creation) to make use of the services provided by it. This process of creating objects (variables) of the class is called class instantiation or instantiating of objects.
  • A class in C++ is –
    • A class in C++ can be described as a collection of data members and member functions.
    • A class in C++ has a class name, a set of attributes (data members/ characteristics), and a set of actions or services(function members/ member functions).
    • The variables(data) declared inside the class of C++ are known as data members/members data and the functions(methods) are known as member functions.

    Object : 

  • An object is an instance of a class.
  • Normally when a class is defined, no memory is allocated but when an object is created (called instantiation) sufficient memory is allocated.
  • When a program is executed, the related objects interact by sending messages to one another.
  • Each normal object (not a static object) contains its separate data part and common function to manipulate the data.
  • Objects can interact with each other without knowing the details of each other’s data or function.
  • Every object under a class has the same data format, and definition and responds in the same manner to an operation.
  • An object may have a name, a set of attributes(member data), and a set of actions/services/ methods.
  • An object may stand alone or it may belong to a class of similar objects.
  • Objects are the basic run-time entities in Object-Oriented programming language. They occupy space in memory that keeps its state and is operated on by the defined operations/functions on the object, while a class defines a possible set of objects.
  • An object in C++ is –
    • It is the most important feature of C++. It makes C++ an Object-Oriented language.
    • An object of a class can access the members of a class. We can access the member of a class using the member assess operator, dot(.). The syntax for assessing the data member of a class is: –  objectName. data member; whereas the syntax for assessing member functions of a class is: –  objectName.functionName(actual arguments, if any);
    • Syntax: –
                  class   className   objectName1, objectName2 … ;     
                                             OR
                  className  objectName1, objectName2 … ;
      • Example –
    class Student stu1;
            class Student stu1, stu2, stu3;       
                                              OR
            Student stu1, stu2, stu3;
      • Objects can also be created by placing their names immediately after the closing brace of the class, similar to ‘structure’ in C. Thus
                    class Student
                        {
                             ………….
                             ………….
                        }stu1, stu2, stu3;

       Abstraction :

      • Data abstraction is one of the most essential features of object-oriented programming in C++.
      • Abstraction is displaying only essential information to the users and hiding the complexity/details.
      • Data abstraction displays only essential information about the data to the outside world, hiding the remaining one in the background or implementation.

       Data Hiding :

      • This is done by declaring data as private and making it accessible only to the class in which it is defined. This concept is called data hiding. In data hiding, the data is hidden inside the class by declaring it as private inside the class. Here function may be public or private.
      • When data or functions are defined as private it can be accessed only by the class in which it is defined.
      • Restrictions of external access to features/members of a class result in data hiding.
      • If the implementation details are not known to the user, it is called information hiding

       Encapsulation :

      • Encapsulation is one of the important characteristics of Object Oriented Programming Language.
      • The property of C++ which allows the wrapping up of data/information and functions into a single unit is called encapsulation.
      • Encapsulation is defined as binding the data and the functions that manipulate them together.
      • It is considered as the most striking feature of a class.
      • Encapsulation also leads to data abstraction or hiding.
      • encapsulation also hides the data.
      • Technically it is a combination of data and related functions together in a bundle.
      • The advantages of encapsulation are data hiding, information hiding, and implementation independence. (The user‟s interface is not affected by changing the implementation mechanism. A change in the implementation is done easily without affecting the interface. This leads to implementation independence.)

      Polymorphism :

      • It is the ability of a message to be displayed in more than one form as per requirements and situations.
      • C++ supports two types of polymorphism – operator overloading and function overloading.
      • Polymorphism is mainly used in implementing inheritance.

      Inheritance :

      • Inheritance is one of the most important features of Object Oriented Programming.
      • It is the capability of a class to derive required properties and characteristics from another class as per requirements is called Inheritance.
      • Inheritance supports the concept of “reusability in which we are reusing the fields and methods of the existing class as per requirements multiple times.
      • it helps in reducing the code size since the common characteristic is placed separately in base class.

      Message Passing : 

      • As we know related Objects communicate with one another by sending and receiving messages to each other for better coordination and processing management.
      • Message passing normally involves specifying the name of the object, the name of the function, and the information to be sent.

      Advantages/Benefits of OOPs

      • OOPs, are very close to real-world phenomena/works.
      • Objects in OOPs show both the state (data) and behavior (function) that is very similar to the real-world objects/works.
      • OOPs are more suitable to handle large & complex projects easily.
      • The projects executed using OOP techniques are more reliable.
      • It provides higher-quality projects.
      • Abstraction techniques of OOPs are used to hide the unnecessary details and focus only on the useful relevant part of the problem and solution.
      • The encapsulation feature of OOPs helps in concentrating the structure as well as the behavior of various objects in OOP in a single enclosure.
      • The information hiding feature of OOPs is used to hide the information and to allow strictly controlled access to the structure as well as the behavior of the objects.
      • OOPs, divide the problems into several objects for solving a particular problem.
      • Object-oriented systems are easier to upgrade/modify.
      • The inheritance and polymorphism features provide the extensibility of the OOP languages.
      • The concepts of OOP also enhance the reusability of the existing code multiple times.
      • In OOPs, Software complexity is managed in a better way.

      Limitations/Demerits of OOPs

      • The size of programs developed with OOP is larger than the procedural approach.
      • The programmer should have proper planning before designing a program using the OOP approach hence it is tricky.
      • Since an OOP program is normally larger, hence more instructions to be executed, which results in a little bit slower execution of programs.

      Loading


      0 Comments

      Leave a Reply

      Your email address will not be published. Required fields are marked *

      This site uses Akismet to reduce spam. Learn how your comment data is processed.