0% found this document useful (0 votes)
64 views7 pages

Design Issues of Oops

This document discusses key design issues in Object-Oriented Programming (OOP) languages, including the treatment of objects, inheritance types, memory allocation, binding methods, nested classes, and object initialization. It highlights the advantages and disadvantages of full object orientation, single vs. multiple inheritance, and the implications of dynamic vs. static binding. The document also summarizes common approaches taken by various programming languages to address these design issues.

Uploaded by

Lalu Pradhap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views7 pages

Design Issues of Oops

This document discusses key design issues in Object-Oriented Programming (OOP) languages, including the treatment of objects, inheritance types, memory allocation, binding methods, nested classes, and object initialization. It highlights the advantages and disadvantages of full object orientation, single vs. multiple inheritance, and the implications of dynamic vs. static binding. The document also summarizes common approaches taken by various programming languages to address these design issues.

Uploaded by

Lalu Pradhap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Design Issues in Object-Oriented

Programming Languages
Object-Oriented Programming (OOP) languages aim to support principles such as
encapsulation, inheritance, polymorphism, and abstraction. Designing language features to
support these involves various important decisions. This guide highlights key design issues in
OOP languages.

🔰 1. Exclusivity of Objects
❓ Design Question:
Should everything be treated as an object, including primitive types?

✅ Advantages of Full Object Orientation:


●​ Uniform syntax and semantics​

●​ Conceptual elegance (as in Smalltalk)​

⚠️ Disadvantages:
●​ Performance overhead: Even simple operations (e.g., integer addition) require
message passing.​

●​ Less efficient than primitive operations in procedural languages.​

🛠️ Common Approaches:
Language Type Strategy

Pure OOP (e.g., Smalltalk) Everything is an object

Hybrid OOP (e.g., C++) Primitive types remain non-objects


Java Primitive types with object wrappers (e.g., int vs
Integer)

🧬 2. Are Subclasses Subtypes?


✅ Principle of Substitution (Liskov Substitution Principle):
If class B extends class A, an object of class B should be usable wherever an object of class
A is expected, without errors or changes in behavior.

🔍 Example in Ada:
ada
CopyEdit
subtype Small_Int is Integer range -100 .. 100;

●​ Small_Int is a subtype of Integer.​

⚖️ Subclass vs. Subtype:


●​ Subtype: Guarantees interface and behavior compatibility.​

●​ Subclass: Inherits implementation, not necessarily behavior.​

🛑 Subtype violations lead to unsafe inheritance.

🏛️ 3. Single vs. Multiple Inheritance


✅ Single Inheritance:
●​ Simpler model​

●​ Easier for compiler and programmer to manage​

●​ Used in Java, C# (with interface-based multiple inheritance)​


✅ Multiple Inheritance:
●​ Allows a class to inherit from multiple parents​

●​ Supported in C++, Python​

⚠️ Challenges:
●​ Diamond Problem:​

cpp
CopyEdit
Z
/ \
A B
\ /
C

●​ Which sum or display() method does C inherit from?​

●​ Causes ambiguity, duplication, or unintended overrides​

🧩 Alternative: Interfaces
●​ Used in Java/C# to simulate multiple inheritance.​

●​ Contains only method signatures, no implementation.​

●​ Avoids diamond inheritance issues.​

🧠 4. Allocation and Deallocation of Objects


❓ Key Questions:
●​ Are objects stack-allocated or heap-allocated?​
●​ Is memory deallocated manually or automatically?​

🧮 Stack Allocation:
●​ Faster, but limited in flexibility​

●​ Can lead to object slicing:​


If subclass object B is assigned to a superclass variable A, subclass-specific fields may
be lost.​

cpp
CopyEdit
class A { int x; };
class B : public A { int y; };

A a1;
B b1;
a1 = b1; // y is sliced off!

🗃️ Heap Allocation:
●​ Objects live longer​

●​ Accessed via pointers/references​

●​ Safer for polymorphism​

🗑️ Deallocation:
●​ Manual: delete in C++​

●​ Automatic: Garbage Collection in Java, Python​

🔗 5. Dynamic vs. Static Binding


✅ Static Binding:
●​ Method is resolved at compile time​

●​ Used for non-virtual methods in C++​

✅ Dynamic Binding:
●​ Method is resolved at runtime​

●​ Supports polymorphism​

●​ Java uses dynamic binding by default for non-static methods​

❓ Design Question:
Should the language support both? Should developers control it?

cpp
CopyEdit
class Base {
virtual void show(); // dynamically bound
};

🧩 6. Nested Classes
✅ Purpose:
●​ Encapsulation: Hides helper classes used only inside other classes​

●​ Scope control: Nested class has access to the enclosing class’s members​

💡 Examples:
●​ Java: Supports static and non-static nested classes (inner classes)​

●​ C++: Supports nested classes with no access to outer members by default​


🏗️ 7. Initialization of Objects
✅ Design Question:
●​ Should object initialization be automatic or manual?​

💡 Language Behaviors:
Languag Behavior
e

C++ Constructors and destructors (can be


user-defined)

Java Constructors, automatic memory management

Python __init__() method for initialization

📑 Summary Table
Design Issue Description/Concern Common Approach

Exclusivity of Are primitives treated as objects? Java: mixed; Smalltalk: fully


Objects object

Subclasses as Liskov Substitution Principle Ada, Java (partial)


Subtypes compliance

Multiple Ambiguity in diamond-shaped Java: interfaces; C++:


Inheritance hierarchies supported with care

Memory Stack vs heap; deallocation type Java: heap + GC; C++: manual
Allocation

Object Slicing Loss of subclass data when Avoided with reference-based


assigning to superclass polymorphism

Dynamic Binding When method implementation is Java: dynamic; C++: controlled


chosen with virtual

Nested Classes Used for scoping and modular design Supported in Java, C++,
Python
Object Manual vs implicit constructors C++/Java: Constructors;
Initialization Python: __init__

You might also like