(OOP) OBJECT ORIENTED PROGRAMMING

(OOP) OBJECT ORIENTED PROGRAMMING

OBJECT ORIENTED PROGRAMMING

You might have heard of OOPS many times. To keep it simple, Object oriented programming is the basic way of thinking or comparing programming with real life objects. ie; thinking programming in the real life way. We have been using this from late 1970’s. Let’s see how they actually work.

Classes are a fundamental part of object-oriented programming. They allow variables and methods to be isolated to specific objects instead of being accessible by all parts of the program. This encapsulation of data protects each class from changes in other parts of the program. By using classes, developers can create structured programs with source code that can be easily modified.

The class is one of the defining ideas of object-oriented programming. Among the important ideas about classes are:

A class can have subclasses that can inherit all or some of the characteristics of the class. In relation to each subclass, the class becomes the superclass.

Subclasses can also define their own methods and variables that are not part of their superclass.

The structure of a class and its subclasses is called the class hierarchy.

Principles of OOPs :

All the programming languages supporting object oriented Programming will be supporting these three main concepts:


  1. Inheritance
  2. Encapsulation
  3. Polymorphism

Inheritance :

When a class acquire the property of another class is known as?inheritance. Inheritance is process of object reusability. Through inheritance, an object acquires some/all properties of another object.


For example:?Car is a classification of Four Wheeler. Here Car acquires the properties of a four-wheeler. Other classifications could be a jeep, tempo, van etc. Four Wheeler defines a class of vehicles that have four wheels, and specific range of engine power, load carrying capacity etc. Car (termed as a sub-class) acquires these properties from Four Wheeler (termed as a super-class), and has some specific properties, which are different from other classifications of Four Wheeler, such as luxury, comfort, shape, size, usage etc.

Encapsulation :

Wrapping up data member and method together into a single unit (i.e. Class) is called Encapsulation. Encapsulation means hiding the internal details of an object, i.e. how an object does something. Hide the data for security such as making the variables as private, and expose the property to access the private data which would be public.


Looking at the example of a power steering mechanism of a car. Power steering of a car is a complex system, which internally have lots of components tightly coupled together, they work synchronously to turn the car in the desired direction. It even controls the power delivered by the engine to the steering wheel. But to the external world there is only one interface is available and rest of the complexity is hidden. Moreover, the steering unit in itself is complete and independent. It does not affect the functioning of any other mechanism.

Similarly, same concept of encapsulation can be applied to code. Encapsulated code should have following characteristics:

  • Everyone knows how to access it.
  • Can be easily used regardless of implementation details.
  • There shouldn’t any side effects of the code, to the rest of the application.

Polymorphism :

Polymorphism?means to process objects differently based on their data type.?Polymorphism is where the method to be invoked is determined at runtime based on the type of the object. This is a situation that results when you have one class inheriting from another and overriding a particular method. However, in a normal inheritance tree, you don’t have to override any methods and therefore not all method calls have to be polymorphic.


Lets us look at same example of a car. A car have a gear transmission system. It has four front gears and one backward gear. When the engine is accelerated then depending upon which gear is engaged different amount power and movement is delivered to the car.

Polymorphism could be static and dynamic both. Overloading is static polymorphism while, overriding is dynamic polymorphism.

  • Overloading?in simple words means two methods having same method name but takes different input parameters. This called static because, which method to be invoked will be decided at the time of compilation
  • Overriding?means a derived class is implementing a method of its super class.

If in an interview if someone ask you to explain polymorphism, better explain it with some example.

“Imagine there is a class called Shape. You have to calculate the area of the shape.But you don’t know which shape will be passed on to calculate the area on run time. It can be a triangle, a square or a rectangle. All these shapes have a common property called area but the way this is calculated is different. So, we create a calculate area function and pass in to it two values.

要查看或添加评论,请登录

Muskan Lalwani的更多文章

  • HADOOP

    HADOOP

    Hadoop is an open-source framework based on Java that manages the storage and processing of large amounts of data for…

  • ETL Workflows

    ETL Workflows

    ETL and ELT overvie As we mentioned before, ETL and ELT are the two ways to?integrate data into a single location. The…

  • Machine Learning

    Machine Learning

    Machine learning is a branch of (AI) and computer science which focuses on the use of data and algorithms to imitate…

  • AWS Lambda

    AWS Lambda

    AWS Lambda is an event-driven, serverless computing platform provided by Amazon as a part of Amazon Web Services. It is…

  • Jenkins

    Jenkins

    Jenkins is an open source continuous integration/continuous delivery and deployment (CI/CD) automation software DevOps…

  • Big Data

    Big Data

    The definition of big data is data that contains greater variety, arriving in increasing volumes and with more…

  • DevOPs

    DevOPs

    DevOps is a methodology in the software development and IT industry. Used as a set of practices and tools, DevOps…

  • AZURE BLOB

    AZURE BLOB

    Azure Blob storage is a feature of Microsoft Azure. It allows users to store large amounts of unstructured data on…

  • TERADATA

    TERADATA

    Teradata is one of the popular Relational Database Management System. It is mainly suitable for building large scale…

  • PySPARK

    PySPARK

    PySpark: A Python API for Apache Spark PySpark is the Python API for Apache Spark, a powerful and scalable data…

社区洞察

其他会员也浏览了