Object Oriented
Object Oriented
Object Oriented
1.1 Association
Association is a relationship where objects are related to each other without implying ownership.
It represents a bi-directional relationship where both objects can interact with each other.
Example:
Library and Book A library contains books, and books are found in a library.
Diagram
+------------+ +-------+
+------------+ +-------+
1.2 Inheritance
Inheritance is a relationship where one class (child) inherits attributes and methods from another
Example
Animal and Dog: A dog is an animal, so the Dog class inherits from the Animal class.
Diagram
+---------+
| Animal |
+---------+
+---------+
| Dog |
+---------+
1.3 Aggregation/Composition
Aggregation is a relationship where one class is a part of another class but can exist
independently. Composition is a stronger form where the part cannot exist without the whole.
Example
Car and Engine (Composition): An engine is a part of a car, and it cannot exist
Diagram
Aggregation:
+-----------+ +--------+
+-----------+ +--------+
Composition:
+------+<>--------+-------+
+------+ +-------+
2.Object oriented systems development uses both an activity diagrams and an interaction
functionality. The most common types are sequence diagrams and collaboration diagrams.
Purpose:
Show the time ordering of messages and how operations are carried out.
| | |
|----Login------>| |
| |---Query------->|
| |<--Result-------|
|<---Success---- | |
| | |
3.Using a suitable example explain how objects communicate in object orientation.
Objects communicate by sending messages to each other, invoking methods or functions that are
Example:
Consider a Bank Account class with a withdraw method. A Customer object may call the
Classes:
class BankAccount {
double balance;
balance -= amount;
System.out.println("Insufficient funds.");
class Customer {
String name;
BankAccount account;
account.withdraw(amount);
Diagram:
+-----------+ +-------------+
| Customer | | BankAccount |
+-----------+ +-------------+
| - name | | - balance |
| - account |<----->| |
+-----------+ +-------------+
+-----------+ +-------------+
4.Explain what the following perspectives used in drawing class diagrams capture
Conceptual Perspective
The conceptual perspective captures the high-level concepts and relationships in the problem
domain without focusing on implementation details. It models real-world entities and their
associations.
Example
Class diagram representing a university with classes like Student, Professor, and Course.
Specification Perspective
The specification perspective details the interfaces, methods, and interactions between classes. It
focuses on how the system will be designed rather than how it will be implemented.
Example
Class diagram showing methods and properties of Student, Professor, and Course classes.
Implementation Perspective
The implementation perspective is concerned with the actual implementation details, including
Example
Class diagram with specific data types and access specifiers for Student, Professor, and
Course classes.
Importance
classes.
behavior.
5. A motor dealer makes an order for various items. An order comprises a list of required
perform operations like adding an item in the order list, deleting an item from the list and
Required:
a) Identify the class (es) in the above description and construct a class diagram showing
class Order {
List<Item> items;
void addItem(Item item) {
items.add(item);
items.remove(item);
double getTotalValue() {
double total = 0;
total += item.getPrice();
return total;
}
class Item {
String nameOfItem;
double itemPrice;
double getPrice() {
return itemPrice;
6. Use the following case to identify Classes and Operations. Associate the operations with
• The telephone book should contain entries for each person in the university
• Users of the directory can look up entries. In addition, the administrator of the
telephone book can, after supplying a password, insert new entries, delete existing entries,
modify existing entries, print the telephone book, and print a listing of all students or of all
faculty.
identified Classes
Telephone Book
Class Diagram
class Person {
String name;
String phoneNumber;
class TelephoneBook {
List<Person> entries;
entries.add(person);
entries.remove(person);
}
void modifyEntry(Person person) {
void printBook() {
void printStudents() {
void printFaculty() {
}
Diagram
+-----------------+
| Person |
+-----------------+
| - name |
| - phoneNumber |
+-----------------+
+-----------------+
| Student |
+-----------------+
+-----------------+
| Professor |
+-----------------+
^
+-----------------+
| Staff |
+-----------------+
+-----------------------+
| TelephoneBook |
+-----------------------+
| - entries |
| +addEntry() |
| +deleteEntry() |
| +modifyEntry() |
| +printBook() |
| +printStudents() |
| +printFaculty() |
+-----------------------+