- 2067 Ashadh (old course) · 10 marks
Characteristics and advantages of OOP
Short answer
OOP characteristics: objects, classes, encapsulation, abstraction, inheritance, polymorphism, dynamic binding, message passing. Main advantages: reusability, modularity, easy maintenance.
What are the characteristics of Object Oriented Programming? What are the main advantage of OOP?
Object-Oriented Programming (OOP) is a programming approach in which a program is organised as a set of objects that combine data (attributes) and the operations (methods) on that data, and that work together by sending messages to each other. Languages such as C++, Java, Python and C# support OOP.
Characteristics of OOP
-
Objects – an object is a run-time entity that has a state (attribute values), behaviour (methods) and a unique identity. Example: a particular bank account with number 1001 and balance Rs. 5000.
-
Classes – a class is a template or blueprint from which objects are created. It defines the attributes and methods that all its objects share. Example: class
Account. -
Encapsulation – data and the methods that act on it are bundled together in a class, and the internal data is hidden (
private). Other objects can access it only through public methods. This is also called information hiding. -
Abstraction – only the essential features are shown to the user and the implementation details are hidden. A user calls
withdraw()without knowing how the balance is stored. -
Inheritance – a new class (subclass) can be derived from an existing class (superclass) and reuse its attributes and methods, adding or overriding some of them. It forms an "is-a" hierarchy. Example:
SavingsAccountis anAccount. -
Polymorphism – one name can have many forms. The same message can produce different behaviour depending on the object that receives it.
- Compile-time: function and operator overloading.
- Run-time: method overriding through virtual functions.
-
Dynamic binding – the method to be executed for a call is decided at run time, based on the actual type of the object. This makes run-time polymorphism possible.
-
Message passing – objects communicate by calling each other's methods (sending messages), e.g.
acc.deposit(500).
+----------------------+
| Account |
|----------------------|
| - accNo |
| - balance |
|----------------------|
| + deposit(amt) |
| + withdraw(amt) |
| + calcInterest() |
+----------------------+
^
+---------+----------+
| |
+------------------+ +------------------+
| SavingsAccount | | CurrentAccount |
|------------------| |------------------|
| + calcInterest() | | + calcInterest() |
+------------------+ +------------------+
Small Java example:
class Account {
private double balance; // encapsulation
public void deposit(double a) { balance += a; }
public double calcInterest() { return 0; }
}
class SavingsAccount extends Account { // inheritance
public double calcInterest() { // polymorphism
return 0.05 * 1000;
}
}
Account a = new SavingsAccount(); // dynamic binding
a.calcInterest(); // calls SavingsAccount version
Advantages of OOP
- Reusability – classes, once written and tested, can be reused in other programs, and inheritance lets new classes reuse existing code.
- Modularity – each class is a self-contained unit, so a large program is split into manageable parts that can be developed and tested separately.
- Easy maintenance – because data is encapsulated, a change inside a class does not affect the rest of the program as long as its interface stays the same.
- Data security – information hiding prevents other parts of the program from changing data accidentally.
- Extensibility – new features are added by creating new subclasses without changing existing, tested code (open-closed principle).
- Real-world modelling – objects map naturally to real things (student, book, account), so the design is easier to understand and to discuss with users.
- Smooth transition from analysis to code – the same object concepts are used in object-oriented analysis (OOA), design (OOD) and programming, so models map directly to code.
- Parallel development and scalability – different teams can work on different classes, which suits large, complex systems.
- Flexibility through polymorphism – code written for a superclass works for any subclass, reducing
if-else/switchcode.
Main drawbacks, for balance: programs can be larger and slightly slower, and good class design needs experience.
✓ Answer checked by Claude Sonnet 5.5
Related questions
- Compare procedural and object oriented programming · Object Oriented Programming, chapter 1
- Advantages of OOP over procedural programming · Object Oriented Programming, chapter 1 · asked 5×
- Features and characteristics of OOP · Object Oriented Programming, chapter 1 · asked 7×
- Object oriented system and core concepts · Object Oriented Analysis and Design, chapter 1