What is OOP?

ByungwookAn
3 min readJul 17, 2024

--

Image source : https://unsplash.com/ko/%EC%82%AC%EC%A7%84/%ED%99%94%EC%9D%B4%ED%8A%B8-%ED%85%8C%EC%9D%B4%EB%B8%94%EC%97%90-%EB%A7%A5%EB%B6%81-%ED%94%84%EB%A1%9C-FoTs3ntRoIs

What is OOP?

Object-Oriented Programming (OOP) is a programming methodology that emulates the real world we perceive by creating basic units called objects and defining their organic interactions to develop programs.

Many of the most widely used programming languages (such as C++, Java, Python, Swift, etc.) are multi-paradigm and support object-oriented programming.

Components of object-oriented programming

  1. Class

Class defines the attributes and methods that an object should have.

2. Object

The instance of a class. An object is an object that operates assigned to memory that actually has properties and methods defined in the class.

3. Method

The method is a function defined within a class that defines the behavior that an object can perform. A method changes the state of an object or interacts with it.

4. Attribute

An attribute is a variable defined within a class that represents the state of an object. An attribute is data that is stored separately for each object.

Characteristics of Object-oriented Programming

  1. Abstraction

Abstraction involves extracting and defining the common attributes and functionalities of objects. In Java, this is achieved through interfaces; in Swift, through protocols; and in C++, through abstract classes. Each class implements the roles defined through abstraction in a context-appropriate manner, which separates the assignment of roles from their implementation.

2. Encapsulation

Encapsulation refers to hiding an object’s attributes and methods from external access and only exposing the necessary parts. Encapsulation is achieved using computed properties (getters and setters) or access modifiers (public, private). By encapsulating, it prevents internal data from being altered to invalid values, thereby maintaining integrity.

3. Inheritance

Inheritance is a feature where one class inherits the attributes and methods of another class. This enhances code reusability, and productivity, and allows for the creation of a hierarchical structure.

4. Polymorphism

Polymorphism is the ability of the same method to perform different actions in different classes. It is an object-oriented feature where an object’s attributes or functionalities can serve different roles depending on the context. Overloading and overriding are prime examples of polymorphism.

Advantages of object-oriented programming

  1. Modularity

Modularity helps minimize code changes and makes maintenance easier.

2. Reusability

Using classes and objects makes code reuse easier. By reusing code, repetitive code is minimized, and the code can be expressed as concisely as possible.

3. Flexibility and Extensibility

By using OOP concepts like inheritance and polymorphism, programs can be easily extended. When adding new features, existing code can be modified minimally, allowing for flexible adaptation.

4. Real-World Modeling

OOP is well-suited for modeling objects and their interactions in the real world. This helps programmers understand and solve problems effectively.

Conclusion

Object-oriented programming (OOP) offers advantages such as easy code extension and maintenance, which can be particularly beneficial for large-scale projects. Moreover, because OOP reflects the real world, it provides a human-friendly and intuitive approach.

Source

--

--