Introduction to Object Oriented Programming ( Java )

Object-oriented programming System(OOPs) is a programming paradigm based on the concept of “objects” and “classes” that contain data and methods. In OOP, a person defines the data type as well as the operations and functions that these classes will perform. Defining it in an easier way we can also say that OOPs provide flexibility and maintainability of programs and make it easier to understand and work with complex systems.

4 - Principles of Object-Oriented Programming

OOPs has 4 main principles they are encapsulation, abstraction, inheritance, and polymorphism.

Encapsulation

  • Encapsulation is the process of bundling data and the functions that operate on that data within a single unit, or object.

  • It helps in the creation of objects that have a well-defined interface, making them user-friendly and maintaining the object.

  • It also secures the data from being accessed and modified directly from outside of a certain defined area.

  • We can implement encapsulation by declaring all the variables in the class as private which will prevent those variables from being accessed and modified outside of that class. So a person has to write public methods in the class to use get and set to access the values of variables indirectly.

Abstraction

  • The process of taking away or ignoring certain details, to focus on the essential features of something.

  • Abstraction allows you to create a simplified, high-level view of an object's characteristics and behavior. You can use abstraction to create an interface that exposes only the most important details about an object. And Ignoring the internal working of that function and more focused on the output that the internal function provides.

Inheritance

  • It is the ability of a class to inherit or access the properties and methods from a parent class.

  • It allows you to create a class that is a modified version of a parent class, without having to recreate all of the original class's functionality. This helps in getting minimized written code without complexities and helps to reduce the redundancy of code.

  • It allows you to create a hierarchy of classes, where each subclass builds on the functionality of its parent class.

Polymorphism

  • The word “poly” means many and “morphs” means forms, So it means many forms.

  • A class can take on multiple forms.

  • It is useful because it allows you to write code that can work with multiple different types of objects flexibly.

  • This can be achieved in several ways, including through inheritance, where a subclass can override or extend the methods of a parent class, or through the implementation of interfaces, which allow a class to adopt a set of methods defined in an interface.

In conclusion, OOPs main goal is to make software that is flexible, maintainable, secure, and doesn't have a not complex structure.