Object Oriented Programming Concept

What is OOP?
Object oriented programming is a way of thinking. It is one of the software development approach. Thinking real world items/things in terms of object.

Different ways of programming

Programming started with the invention of computers. Programming is nothing but giving instructions to the computer or machine.

  • Machine language (bits)
  • Assembly Language (Example ADD A,C)
  • Structured programming( if- else, functions) Emphasis on functionality and not on data. Sharing data globally
  • Object Oriented Programming

Example :

Badminton court online booking.

There are basically 2 categories of people: 1 Technical 2. Non-Technical. It is not necessary that person who gives you requirement as technical back ground. It becomes difficult for non-technical person to interact with technical person.

Technical person thinks in terms of language to use(Asp.net, Angular js), database (oracle, Mysql, SQL), hosting environment etc.
Non technical person thinks in terms of users, number of courts, availability, security guards, light supply etc.

In real life we talk about objects and not functionality. In day-to-day life we come across multiple objects like TV, Fan,watch, Car,AC etc.All these are objects and we are thinking in terms of object. So there was need to correlate/represent these objects with software to be developed.

Court ——————-> Court object

User ———————> User Object

Booking —————–> Booking object

Way of simulating real life thinks into code is nothing but object oriented programming.

Object Oriented Programming Pillars

    • Objects : Object is instance of a class.
      • Attributes and functionality(behavior)
      • Example Court
        • Court attributes: Size/Dimension, surface(grass, tiles, soil, cement),  color
        • Functionality: DoCourtBooking()/ DoCourtCleaning()
      • Attributes are variables or data-members and Functionality is function.
    • Class :
      • Class is blueprint of object. It is specification of the object. How object will look like.
      • Example Student:
        • Attributes: Name, marks,RollNo
        • Functionality: SetMarks(),GetMark(), ExtracurricullarPerformance()
        • Change in attribute results in change in behavior. As the students mark changes, his performance improves.
      • Example 2 – Transaction class
        • Attribute: TransactionID, Amount, TransactionYear
        • Functionality: AddTransaction(), UpdateTransaction(), DeleteTransaction()

  • Abstraction:
    • It is way of showing the necessary details and ignoring the rest.
    • Example Student class:
      • Attributes: There are multiple attributes of student like his Name, RollNo, height, weight, address, hobbies, friends, Age, Marks, shoe size etc. Out of this we need to select few which are required for our application.
      • Here we select Name, RollNo, Marks – This is one view point of abstraction to pick required attributes
      • Behaviour: Communction skills, punctionality, Sports, curricularPerformance etc.
      • Here we pick curricularPerformance  and extra- curricularPerformance
    • For developers pick relevant attributes and function
    • Second part of abstraction – API development
      • We don’t know the implementation part nor bother about it.
  • Encapsulation:
    • Data and functionality is encapsulated within class.
    • Controlling the access of data using access specifier.
    • Capsule :
    • Correlation: Medicine Capsule:
      • In order to prevent any reaction with atmospheric ingredient, medicine content is added in capsule for protection.
    • Similarly in software application we need to protect data.
    • First we put attributes and function within class
    • Second we use access specifier to achieve encapsulation.
    • Different access specifier: Private, protected, internal, public.
    • Ideally attributes are marked private and required functions are made public.
    • Example: AC
      • We have remote as interface to increase temp, decrease temp, on/off
  • Polymorphism
    • Having many forms
    • Same function applied on different object gives you different results.
    • Static polymorphism:
      • Function overloading
      • Operator Overloading
    • Runtime polymorphism
      • Virtual method
    • Example Washing vegetables:
      • Washing potatoes, brinjal and tomatoes.
      • Same command of washing is different for each vegetable based on its class.
  • Inheritance
    • Deriving a class from another class is called inheritance.
    • Creating object using the properties of parent is called inheritance
    • In real life there is relation ship. object works in terms of relation ship
      • Country – Citizen, Parent- Child, Teacher – student
    • Inheritance is way to simulate relationship.
    • Re-usability + Extensibility