top of page
hv

Object-Oriented Programming

Object-Oriented Programming (OOP) is a programming paradigm based on the concept of objects, which can contain data, in the form of fields (otherwise known as attributes or properties) and code, in the form of procedures (which are also known as methods).


There are 4 principles of object-oriented programming. They are:

  1. Encapsulation

  2. Abstraction

  3. Inheritance

  4. Polymorphism

Encapsulation


If there is a program that contains logically dissimilar objects that need to communicate with each other, encapsulation is used. It is achieved when each object keeps its state private and within a class. Other objects do not have access to this state directly, but can only call a list of public functions known as methods. The object manages its own state using methods and no other class can access it unless permission is granted. If communication with the object needs to take place, methods may be used but the state cannot be changed.


Abstraction


Abstraction can be considered to be the natural extension of encapsulation. In OOP design, programs are usually very lengthy, where many different objects communicate with each other. So, in order to maintain a large codebase that needs to accommodate changes, abstraction can be used. Applying abstraction means that each object should only allow a higher level mechanism for using it. This mechanism should hide the information on implementation and only show the operations that are necessary for other objects. The mechanism should be easy to use and rarely change.


Inheritance


Objects are often very similar and share common logic, but are not entirely the same. To reuse common logic and extract the unique logic into a separate class, we use inheritance. Inheritance is when a child class is created by deriving from another parent class, which forms a hierarchy. This way, each class only adds what is necessary for it while reusing the common logic with the parent class.


Polymorphism


Assume there is a parent class and a few child classes which inherit from it, and the user wants to use a collection, such as a list, that contains a mix of the classes or have a method implemented from the parent class but would also like for it to be used on the children. This problem can be solved using polymorphism. Polymorphism means ''many shapes'' in Greek. It gives a way to use a class like its parent so there is no confusion in mixing the types and allows the child class to retain its methods as they are. This happens by defining a parent class’ interface to be reused. A number of common methods are outlined, and then, each child class is allowed to implement its own version of the methods. Any time a collection or a method expects an instance of the parent class, the language takes care of evaluating the right implementation of the common method, regardless of which child class is passed.


Uses of OOP


OOP can be used in multiple situations such as:

  1. Client-server systems

  2. Object-oriented databases

  3. The internet

  4. Real-time system design

  5. Simulation and modelling systems

  6. Hypertext and hypermedia

  7. Neural networking

  8. Parallel programming

  9. Office automation systems

  10. Email

  11. Word processing

  12. Web calendars

  13. Desktop publishing

  14. CIM/CAD/CAM systems


Article was written for CyberClubNPSi

0 views

Recent Posts

See All

Comments


bottom of page