Dec 2020 Object Oriented Technology
Dec 2020 Object Oriented Technology
Object Definition
● Memory is allocated at compile time. Commented [1]: When memory is allocated at compile
● Object is stored in the stack memory. time, it means that the computer reserves the required
memory for variables and data before the program
starts running. This memory is fixed and cannot be
Example:
changed while the program is running. This is typically
done for variables and data structures with a known,
fixed size.
● Memory is allocated at runtime using pointers and the new keyword. Commented [2]: Got it! Let's break it down into the
● Object is stored in the heap memory. simplest terms:
Diagram: Memory Allocation So, using pointers and the `new` keyword lets you
create and manage new memory spaces while your
program is running.
Conclusion:
● An Abstract Data Type (ADT) is a data structure defined by what it does rather than how it is implemented.
● ADTs hide the internal implementation and only expose the operations (methods) that can be performed.
● Example: A Stack ADT allows push() and pop(), but hides its internal array or linked list implementation.
● The object-oriented model supports ADTs using classes that define data (attributes) and operations (methods).
● Encapsulation means bundling data (attributes) & methods (functions) into single unit (class).
● Restricts direct access to data & ensures that data is modified only through controlled operations.
● Access specifiers help enforce encapsulation:
○ private → Data is fully hidden (only accessible inside the class).
○ protected → Data is partially hidden (accessible inside the class and derived classes).
○ public → Data is fully exposed (accessible from outside the class).
ADTs define what operations can be performed, but hide the implementation.
Encapsulation ensures that data is protected and only modified through defined methods.
Together, they create modular, reusable, and secure object-oriented programs.
1. Abstraction
Definition: Hiding complex implementation details and exposing only essential features.
Purpose: Reduces complexity, improves security, and enhances code readability.
Example:
● A Car has a start() and drive() function, but users don’t need to know the internal engine
mechanics.
class Car {
public:
void start() { cout << "Car started"; }
void drive() { cout << "Driving..."; }
private:
int engineStatus; // Hidden details
};
Diagram:
+--------------+
| Car |
+--------------+
| - engineStatus | (Hidden details)
+--------------+
| + start() | (Visible function)
| + drive() |
+--------------+
Memorization Tip:
Think of a TV remote—you press buttons without knowing the internal circuits!
2. Encapsulation
Definition: Bundling data and methods inside a class while restricting direct access.
Purpose: Protects data and ensures controlled modifications.
Example:
● A BankAccount class hides the balance variable and provides deposit() to update it.
class BankAccount {
private:
double balance; // Hidden data
public:
void deposit(double amount) { balance += amount; }
double getBalance() { return balance; }
};
Diagram:
+----------------------+
| BankAccount |
+----------------------+
| - balance: double | (Hidden)
+----------------------+
| + deposit(amount) | (Controlled access)
| + getBalance() |
+----------------------+
Memorization Tip:
Think of capsules in medicine—they encapsulate ingredients so you only get the benefits!
3. Inheritance
Definition: A class (child) derives attributes and behavior from another class (parent).
Purpose: Promotes code reuse, avoids redundancy, and supports hierarchy.
Example:
class Animal {
public:
void eat() { cout << "Eating..."; }
};
Diagram:
Animal (Parent Class)
+------------------+
| + eat() |
+------------------+
|
| Inherits
↓
Dog (Child Class)
+------------------+
| + bark() |
+------------------+
Memorization Tip:
Think of a family tree—a child inherits traits from parents!
4. Polymorphism
class Animal {
public:
virtual void sound() { cout << "Some sound"; }
};
int main() {
Animal* myDog = new Dog();
myDog->sound(); // Outputs: Bark
}
Diagram:
+--------------+
| Animal |
+--------------+
| + sound() | --> Default sound
+--------------+
|
↓
+--------------+
| Dog |
+--------------+
| + sound() | --> Bark
+--------------+
Memorization Tip:
Think of a universal remote—one remote controls multiple devices differently!
Inheritance Child class inherits from parent Dog inherits Animal.eat() Family tree
AEIP = OOP
1. Objects
Example in C++:
class Car {
public:
string color;
void drive() { cout << "Car is driving"; }
};
2. Classes
Example in C++:
class Car {
public:
string model;
void honk() { cout << "Beep Beep"; }
};
int main() {
Car myCar; // Object of class Car
myCar.honk();
}
3. Abstraction
class Car {
public:
void start() { cout << "Car started"; } // Users don't see internal engine details
};
4. Encapsulation
class BankAccount {
private:
double balance; // Hidden data
public:
void deposit(double amount) { balance += amount; }
double getBalance() { return balance; }
};
5. Inheritance
Allows a child class to inherit properties and methods from a parent class.
Promotes code reuse and reduces redundancy.
class Animal {
public:
void eat() { cout << "Eating..."; }
};
6. Polymorphism
class Animal {
public:
virtual void sound() { cout << "Some sound"; }
};
Performance Considerations
Platform Compatibility
3. a) What are the basic elements of a use case diagram? What is the use of a context diagram?
Definition: A Use Case Diagram shows how users (actors) interact with a system to achieve a goal.
Actors
Example:
Customer logs in and places an order in an online shopping system.
Diagram Representation:
Use Cases
Example:
● Login
● Place Order
● Make Payment
Diagram Representation:
System Boundary
Example:
Diagram Representation:
Relationships
Types:
Association (—) → Normal interaction between actor & use case.
Include (<>) → Mandatory use case that must be executed.
Extend (<>) → Optional use case triggered under specific conditions.
Example:
Diagram Representation:
Context Diagram
Definition: A Context Diagram provides a high-level view of a system, showing:
System Boundary (Entire system as one entity).
External Entities (Users, other systems).
Data Flow (Information exchanged).
Purpose:
Helps understand system scope and external interactions.
Useful in requirement analysis.
Memorization Tips
● A → Actors (Users)
● P → Processes (Use Cases)
● S → System Boundary (Scope)
● R → Relationships (How they interact)
3. b) Provide an example for use case generalization. What is its significance? Provide an example for actor
generalization. What is the significance of generalizing or specializing actors?
Definition:
Use Case Generalization allows a general use case to be specialized into more specific use cases that inherit
common behavior.
Purpose:
Reduces redundancy in use case diagrams.
Ensures reusability of common functionalities.
Diagram Representation:
Actor Generalization
Definition:
Actor Generalization allows a general actor to be specialized into specific roles that inherit common interactions.
Purpose:
Helps define role-based access in a system.
Allows different actors to share common functionality.
Specialized Actors:
Diagram Representation:
Memorization Tips
● Think of a parent-child relationship where common features are inherited by specific cases.
● Example Trick: "Pay once, but choose how!" (Make Payment → Credit Card / PayPal)
● Think of job roles—a general role (User) can have different job positions (Admin, Customer).
● Example Trick: "One big boss (User), different employees (Admin, Customer)!"
4. a) Explain, with an example, how you would create space for an array of objects using pointers.
Definition: Dynamic memory allocation involves using pointers and the new keyword to create an array of objects
at runtime.
Flexibility: Allows for flexible memory allocation when the number of objects is unknown beforehand.
Diagram Representation
Memorization Tips
Use the "C.A.S.D." Rule:
● C – Create a class.
● A – Allocate an array dynamically.
● S – Set values and access objects.
● D – Delete memory using delete[].
Trick to Remember:
Think of new Car[n] as reserving parking spaces for n cars!
4. b) Declare a class called `logic_gate` to represent logic gates. Derive `NAND_gate` and `NOR_gate` from it
and demonstrate dynamic polymorphism.
Explanation
Polymorphism allows different gate types (NAND, NOR) to be used via a base class pointer.
Pure virtual function (= 0) makes logic_gate an abstract class.
Dynamic memory allocation (new) ensures flexibility at runtime.
Diagram Representation
Memorization Tips
Trick to Remember:
Think of logic_gate as a universal adapter—NAND & NOR plug into it!
5. a) What is distributed object modelling? How is it useful for implementing an object-based distributed system?
Distributed Object Modelling is a technique used to design and represent objects that interact across a
network in a distributed system.
Objects are located on different computers, but they communicate as if they were in the same system.
Uses middleware like CORBA, RMI, and DCOM to manage communication between objects.
Enables Scalability – Objects can exist across multiple machines, improving performance.
Encapsulation & Modularity – Each object performs specific tasks, making the system easier to manage.
Reusability – Objects can be reused across different applications.
Fault Tolerance – If one server fails, other objects can continue functioning.
Platform Independence – Objects can communicate between different operating systems and languages.
● Objects interact over a network using stubs (client-side) and skeletons (server-side).
● Example: Java RMI (Remote Method Invocation) enables Java objects on different machines to
communicate.
2. Middleware Support
● Middleware like CORBA (Common Object Request Broker Architecture) allows communication
between objects in different languages.
4. Location Transparency
Memorization Tips
Trick to Remember:
Think of distributed objects as “WhatsApp messages” – sent from one device but accessible
anywhere!
CORBA (Common Object Request Broker Architecture) is a middleware standard developed by the
Object Management Group (OMG) for enabling distributed object communication.
It allows objects written in different programming languages to communicate over a network seamlessly.
Uses an Object Request Broker (ORB) to manage communication between client and server objects.
Language & Platform Independence – Supports C++, Java, Python, and more.
Interoperability – Enables different applications to work together, regardless of their programming languages.
Transparency – Hides the details of object location and communication.
Scalability – Works in small systems and large enterprise applications.
Security – Supports authentication and encryption.
CORBA Architecture
1. Define Object Interface – The developer writes an interface using IDL (Interface Definition Language).
2. Generate Stubs & Skeletons – The IDL compiler generates client stubs and server skeletons.
3. Client Makes a Request – The client invokes a method on a remote object using the stub.
4. ORB Routes the Request – The ORB forwards the request to the appropriate server.
5. Server Processes the Request – The server object executes the method and sends the result back.
Client Code
Diagram Representation
Advantages of CORBA
Disadvantages of CORBA
Memorization Tips
Use "C.O.R.B.A." Rule:
Trick to Remember:
Think of CORBA like an "international translator" – it helps different languages communicate over a
network!
6. a) Describe the syntax of single and multiple inheritance. When do we use such types of inheritance? Provide
examples and diagrams.
What is Inheritance?
Inheritance is an Object-Oriented Programming (OOP) feature that allows a child class to inherit properties
and behaviors (methods) from a parent class.
Helps in code reusability, modularity, and scalability.
Single Inheritance
Syntax:
Example:
Diagram Representation:
Multiple Inheritance
Syntax:
Example:
Diagram Representation:
Use Single Inheritance when extending a single class's functionality (e.g., Dog inherits from Animal).
Use Multiple Inheritance when the child class needs functionalities from multiple sources (e.g., a Child
inheriting traits from both Mother and Father).
Avoid Multiple Inheritance when it can create ambiguity issues (diamond problem).
Memorization Tips
6. b) Declare a class called `item`. Derive `employee` and `customer` from it.
Implementation of the item class with employee and customer as derived classes.
📌 Diagram Representation
🎯 Memorization Tips
Think of Item as a "Product" in a Store – Common for both employees and customers.
Employee Manages Items, Customer Buys Items – So both inherit from Item.
Use Simple Naming – setItem(), displayItem(), etc., for clarity.
This example demonstrates inheritance, data encapsulation, and class hierarchy in a simple and easy-to-
understand way.
7. a) What are distributed objects? Discuss various methods to remotely invoke these objects.
Definition:
● Distributed objects are objects that reside on different machines (servers or clients) in a network but
behave as if they are part of the same application.
● They enable communication across systems using remote method invocation (RMI) or other
mechanisms.
Key Features:
Example:
● A banking system where a remote "Account" object is accessed by different users for transactions.
Definition:
● RMI allows a program to call methods on an object located in a different JVM (Java Virtual Machine) over
a network.
How it Works?
● Client makes a request → Stub (proxy) forwards it → Server processes & returns result.
Definition:
● CORBA enables cross-platform communication between distributed objects using IDL (Interface
Definition Language).
How it Works?
● Uses an ORB (Object Request Broker) to manage requests between clients and servers.
Definition:
How it Works?
● Client sends an XML request → Web service processes → Returns XML response.
Definition:
● A lightweight architectural style using HTTP methods (GET, POST, etc.) for communication.
How it Works?
Memorization Tricks
Analogy to Remember:
RMI → "Calling a friend with the same phone brand" (Java-to-Java).
CORBA → "Calling across different phone brands" (Cross-language).
SOAP → "Sending a formal letter" (Structured XML).
REST → "Sending a quick text message" (Simple, lightweight).
Summary
Final Thought:
Choose the right method based on system requirements!
7. b) What are object-oriented databases? How are they different from relational databases?
Definition:
● Object-Oriented Databases (OODB) store data in the form of objects, similar to object-oriented
programming (OOP).
● They integrate database management with object-oriented principles, such as encapsulation,
inheritance, and polymorphism.
Key Features:
Example:
● A university database where Student, Course, and Professor are objects rather than relational tables.
● You have complex, hierarchical data (e.g., medical imaging, CAD, AI).
● You need faster access to objects without complex joins.
Memorization Tricks
● OODB is like a bookshelf with objects (books, notebooks, etc.) stored as they are.
● RDBMS is like an Excel sheet where every entry fits into a row and column.
Summary
OODB stores objects & supports inheritance and encapsulation.
RDBMS stores structured data in tables with SQL queries.
OODB is best for complex applications, while RDBMS is ideal for structured data handling.
Final Thought:
OODB extends OOP principles to databases, while RDBMS remains efficient for transactional data. Choose
wisely!
a) Gemstone / O2 / Orion
🔹 Gemstone
Definition:
● An Object-Oriented Database Management System (OODBMS) that supports complex data types and
object relationships.
Features:
Use Case:
🔹 O2
Definition:
Features:
Use Case:
🔹 Orion
Definition:
Features:
Use Case:
Definition:
● A base class declared as virtual to prevent multiple copies of the same base class when using
multiple inheritance.
Example:
Definition:
Use Case:
d) Booch Methodology
Definition:
Key Features:
Object Modeling: Defines objects, attributes, and behaviors.
Class Identification: Identifies reusable classes in a system.
Dynamic Behavior Modeling: Describes object interactions over time.
Diagram Notation: Uses Clouds & Graphs to represent objects.
Example:
● Used in large-scale software development, such as military, aerospace, and enterprise software.
Significance:
Final Thought:
Understanding these concepts helps in designing efficient object-oriented and database-driven systems!