Jacobvu84 / retrieving-weather-data

Retrieving Historical Weather Data Hourly
0 stars 0 forks source link

What is OOP ? #6

Open Jacobvu84 opened 10 months ago

Jacobvu84 commented 10 months ago

OOP stands for Object-Oriented Programming, which is a programming paradigm based on the concept of "objects." In OOP, a program is organized into objects that represent real-world entities, and these objects can interact with each other to perform tasks. The four main principles of OOP are encapsulation, inheritance, polymorphism, and abstraction.

1. Encapsulation:

2. Inheritance:

3. Polymorphism:

4. Abstraction:

Encapsulation: Encapsulation refers to the bundling of data (attributes) and the methods (functions) that operate on the data into a single unit known as a class. The class serves as a blueprint for creating objects, and encapsulation helps hide the internal details of how an object works, exposing only what is necessary.

Inheritance: Inheritance is a mechanism that allows a class to inherit properties and behaviors from another class. The class that is being inherited from is called the superclass or parent class, and the class that inherits is called the subclass or child class. This promotes code reusability and helps create a hierarchy of classes.

Polymorphism: Polymorphism allows objects of different classes to be treated as objects of a common base class. It enables a single interface to represent different types or forms. There are two types of polymorphism: compile-time (method overloading) and runtime (method overriding).

Abstraction: Abstraction involves simplifying complex systems by modeling classes based on the essential properties and behaviors they share. It allows developers to focus on the relevant features of an object while ignoring unnecessary details.

Jacobvu84 commented 10 months ago

Object-Oriented Programming (OOP) is a programming paradigm that uses objects and classes for organizing code. The four main pillars of OOP are:

1. Encapsulation:

2. Inheritance:

3. Polymorphism:

4. Abstraction:

Jacobvu84 commented 8 months ago

What are the main principles of OOP? Object-oriented programming is based on the following principles:

Encapsulation. This principle states that all important information is contained inside an object and only select information is exposed. The implementation and state of each object are privately held inside a defined class. Other objects do not have access to this class or the authority to make changes. They are only able to call a list of public functions or methods. This characteristic of data hiding provides greater program security and avoids unintended data corruption.

Abstraction. Objects only reveal internal mechanisms that are relevant for the use of other objects, hiding any unnecessary implementation code. The derived class can have its functionality extended. This concept can help developers more easily make additional changes or additions over time.

Inheritance. Classes can reuse code from other classes. Relationships and subclasses between objects can be assigned, enabling developers to reuse common logic while still maintaining a unique hierarchy. This property of OOP forces a more thorough data analysis, reduces development time and ensures a higher level of accuracy.

Polymorphism. Objects are designed to share behaviors and they can take on more than one form. The program will determine which meaning or usage is necessary for each execution of that object from a parent class, reducing the need to duplicate code. A child class is then created, which extends the functionality of the parent class. Polymorphism allows different types of objects to pass through the same interface.