Object-Oriented Programming (OOP) is a programming paradigm based on the concept of objects.
In OOP, objects are instances of classes, and these objects can contain both data (attributes or properties) and code (methods or functions).
OOP is a way to structure the code using objects and classes.
-
Encapsulation: This involves bundling the data (attributes) and the methods that operate on the data into a single unit, known as a class. Encapsulation helps in hiding the internal state of objects and only exposes the necessary functionalities.
-
Abstraction: Abstraction focuses on showing only the necessary details of an object and hiding its complexity. It allows programmers to work with high-level models without concerning themselves with the nitty-gritty implementation details.
-
Inheritance: Inheritance allows a class (subclass or child class) to inherit properties and behaviors from another class (superclass or parent class). This facilitates code reuse and allows for the creation of hierarchical relationships between classes.
-
Polymorphism: Polymorphism means having the ability to take different forms. In OOP, it allows objects of different classes to be treated as objects of a common superclass. This allows for flexibility in handling different types of objects through a uniform interface.
Design principles are guidelines/best practices for creating maintainable, flexible, and understandable software.
OOP provides a way to structure the code using objects and classes, design principles guide how to create these objects and classes effectively.
The design pattern is a general repeatable solution to a commonly occurring problem in software design.
Principles are rules while patterns are their concrete example.