Estimated reading: 4 minutes 155 Views

Object-oriented programming

Object-oriented programming is a methodology or paradigm to design a program using classes and objects. It has many advantages like:

  • Reusability.
  • Readability.
  • Performance.
  • Space.

Object-Oriented Programming (OOP) is a programming paradigm that revolves around the concept of objects. Java is a powerful and widely-used programming language that fully supports OOP principles.

Other languages that support OOP: Python, C++, Visual Basic, NET and Ruby.

There are other methodologies like:

  • Procedural programming that is used by C, Pascal, COBOL, FORTRAN, Java, Python, C++ ..etc.
  • Event-driven that is used by C#, Visual Basic, Visual C++ and Java.

Objects are fundamental building blocks in object-oriented programming (OOP) and play a crucial role in the design and implementation of systems. To illustrate this concept, let’s consider the example of designing a store system.

When we think about building a store system, the first thing that comes to mind is the objects involved. In this case, we can identify three main objects: products, customers, and payment methods.

Products: Products represent the items that the store sells. These could be anything from groceries to electronics or clothing. Each product in the store is characterized by its unique attributes such as name, price, quantity, and category. In OOP, products can be represented as objects with properties and behaviors. For example, we could have a Product class with attributes like name, price, and quantity, and methods to update product information or check availability.

Customers: Customers are individuals or entities who visit the store to purchase products. They interact with the store by browsing products, selecting items for purchase, and completing transactions. In OOP, customers can be modeled as objects with attributes such as name, address, contact information, and purchase history. We could have a Customer class with methods to place orders, view order history, or update personal details.

Payment Method: Payment methods are mechanisms used by customers to pay for their purchases. These could include cash, credit/debit cards, mobile wallets, or online payment gateways. Each payment method has its own set of rules and procedures for processing transactions. In OOP, payment methods can be represented as objects with properties and behaviors related to processing payments. We could define different payment method classes with methods to authorize payments, handle refunds, or generate transaction receipts.

By identifying these objects and their relationships, we can design a cohesive and modular store system that encapsulates the functionality of managing products, serving customers, and processing payments. Each object in the system encapsulates its own state and behavior, promoting encapsulation, modularity, and code reuse, which are key principles of object-oriented programming.


Objects in object-oriented programming (OOP) are composed of two essential members: data (properties, attributes) and operations (methods, functions, behaviors). These elements encapsulate the state and behavior of the object, respectively, and work together to represent real-world entities within a software system.

Let’s explore the car example to better understand these concepts:

  1. Attributes:
    Name: Represents the brand or manufacturer of the car.
    Max Speed: Indicates the maximum speed the car can achieve.
    Price: Denotes the cost or price of the car.
    Model: Represents the specific model or version of the car.
  2. Operations:
    move(): Represents the action of moving the car. This method may involve starting the engine, accelerating, braking, and steering.
    calculateVehicleAge(): Calculates the age of the car based on its manufacturing year or model year.
  3. Getters and Setters:
    get(): Getter methods retrieve the current value of an attribute.
    set(): Setter methods modify or update the value of an attribute.

For example, in the car class, we may have getter and setter methods for each attribute, such as getName() and setName() for the name attribute, getMaxSpeed() and setMaxSpeed() for the max speed attribute, and so on. These methods allow external code to access and modify the state of the car object in a controlled manner, promoting encapsulation and data integrity.

Additionally, the class diagram is a graphical representation of the structure and relationships of classes in a software system. It visually depicts the classes, their attributes, methods, and associations with other classes. Class diagrams provide a high-level overview of the system’s architecture and help developers understand the relationships between different components.


In object-oriented programming (OOP), a class is a blueprint or template that defines the structure and behavior of objects. It serves as a blueprint for creating objects with similar characteristics and functionalities. Classes encapsulate data (attributes) and operations (methods) into a single unit, providing a modular and reusable way to model real-world entities within a software system.


Share this


Or copy link