The document provides an overview of Object-Oriented Analysis and Design (OOAD), focusing on the nature of objects and classes, their relationships, and principles for building quality classes and objects. It discusses key concepts such as state, behavior, identity, association, aggregation, composition, inheritance, and dependency. Additionally, it emphasizes the importance of classification in organizing complex systems and creating reusable components.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
14 views46 pages
OOAD Unit 2
The document provides an overview of Object-Oriented Analysis and Design (OOAD), focusing on the nature of objects and classes, their relationships, and principles for building quality classes and objects. It discusses key concepts such as state, behavior, identity, association, aggregation, composition, inheritance, and dependency. Additionally, it emphasizes the importance of classification in organizing complex systems and creating reusable components.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 46
OBJECT ORIENTED
ANALYSIS AND DESIGN
Unit-2: Classes and Objects BCA Sem-IV 1. Nature of an Object In Object-Oriented Analysis and Design (OOAD), the nature of an object refers to its characteristics and behaviors that define its role in the system being modeled. An object is an instance of a class, and its nature is determined by the following key aspects: State: The state of an object is represented by the values of its attributes or properties. These attributes hold the data that describes the object's current condition. For example, in a class Car, the state could include attributes like color, speed, and fuelLevel. 1. Nature of an Object Behavior: The behavior of an object is defined by the methods or functions that it can perform. These methods are typically responsible for changing the object's state or interacting with other objects. For example, the Car class might have methods like accelerate(), brake(), and refuel() that modify the car's state. Identity: Every object has a unique identity that distinguishes it from other objects, even if their states and behaviors are identical. This identity allows us to refer to a specific instance, ensuring that objects are treated as individual entities. For instance, even if two Car objects have the same state, they are still distinct objects with unique identities. 2. Relationships among objects In Object-Oriented Analysis and Design (OOAD), the relationships between objects are crucial for defining how different objects interact within the system. Here are the key types of relationships among objects: 1. Association The association represents a relationship between two or more objects where they are connected through a link. It can be a one-to-one, one-to-many, or many-to-many relationship. For example, a "Student" object may be associated with a "Course" object through an enrollment relationship. 2. Relationships among objects 2. Aggregation Aggregation is a special form of association where a part-whole relationship exists between objects, and the part (child) can exist independently of the whole (parent). For example, a "Car" object can have an "Engine" object as a part, but the engine can exist outside the car. 3. Composition Composition is a stronger form of aggregation where the part (child) cannot exist without the whole (parent). For example, a "House" object may be composed of "Room" objects, and if the house is destroyed, the rooms are also destroyed. 2. Relationships among objects 4. Inheritance Inheritance is a mechanism where one class (subclass or child class) inherits properties and behaviors from another class (superclass or parent class). It allows for code reuse and supports the "is-a" relationship. For example, a "Dog" class can inherit from an "Animal" class. 5. Dependency Dependency represents a relationship where one class (client) depends on another class (supplier) for its functionality. If the supplier class changes, the client class may need to be modified. For example, a "Person" class may depend on a "Car" class to drive, but the person can exist without the car. 3. Nature of Class In Object-Oriented Analysis and Design (OOAD), a "class" represents a blueprint or template that defines the structure (data attributes) and behavior (methods) of a group of objects with shared characteristics, essentially acting as a pattern for creating individual objects with similar properties and functionalities; it's like a blueprint for a building where each house built from that plan is an "object" with the same design but potentially different details. 3. Nature of Class Key points about the nature of a class in OOAD: Abstraction: A class encapsulates the essential details of an object, hiding internal implementation complexities and providing a simplified interface to interact with it. Encapsulation: A class bundles data (attributes) and methods (functions) together, restricting direct access to data and enforcing data integrity through controlled methods. Inheritance: Classes can inherit properties and behaviors from other classes (parent classes), allowing for code reuse and creating a hierarchical relationship. Object Instantiation: Each object created within a system is considered an "instance" of a class, meaning it is a specific realization of the class with its own unique data values. 3. Nature of Class Example: Class: "Car"Attributes: color, model, year, speed Methods: accelerate, brake, turn Object: "MyHondaCivic" (an instance of the "Car" class)Properties: color: red, model: Civic, year: 2020, speed: 50 mph 4. Relationship among classes Relationships between classes describe how classes are connected or interact with each other within a system. There are several types of relationships in object-oriented modeling, each serving a specific purpose. Here are some common types of relationships in class diagrams: 4. Relationship among classes 4. Relationship among classes 1. Association An association represents a bi-directional relationship between two classes. It indicates that instances of one class are connected to instances of another class. Associations are typically depicted as a solid line connecting the classes, with optional arrows indicating the direction of the relationship. Let’s consider a simple system for managing a library. In this system, we have two main entities: Book and Library. Each Library contains multiple Books, and each Book belongs to a specific Library. This relationship between Library and Book represents an association. 4. Relationship among classes 4. Relationship among classes 2. Directed Association: A directed association represents a relationship between two classes where the association has a direction, indicating that one class is associated with another in a specific way. In a directed association, an arrowhead is added to the association line to indicate the direction of the relationship. Directed associations are used when the association has a specific flow or directionality, such as indicating which class is responsible for initiating the association or which class has a dependency on another. Consider a scenario where a “Teacher” class is associated with a “Course” class in a university system. The directed association arrow may point from the “Teacher” class to the “Course” class, indicating that a teacher is associated with or teaches a specific course. 4. Relationship among classes 4. Relationship among classes 3. Aggregation Aggregation is a specialized form of association that represents a “whole-part” relationship. It denotes a stronger relationship where one class (the whole) contains or is composed of another class (the part). Aggregation is represented by a diamond shape on the side of the whole class. In this kind of relationship, the child class can exist independently of its parent class. Let’s understand aggregation using an example: The company can be considered as the whole, while the employees are the parts. Employees belong to the company, and the company can have multiple employees. However, if the company ceases to exist, the employees can still exist independently. 4. Relationship among classes 4. Relationship among classes 4. Composition Composition is a stronger form of aggregation, indicating a more significant ownership or dependency relationship. In composition, the part class cannot exist independently of the whole class. Composition is represented by a filled diamond shape on the side of the whole class. Let’s understand Composition using an example: Imagine a digital contact book application. The contact book is the whole, and each contact entry is a part. Each contact entry is fully owned and managed by the contact book. If the contact book is deleted or destroyed, all associated contact entries are also removed. 4. Relationship among classes 4. Relationship among classes 5. Generalization(Inheritance) Inheritance represents an “is-a” relationship between classes, where one class (the subclass or child) inherits the properties and behaviors of another class (the superclass or parent). Inheritance is depicted by a solid line with a closed, hollow arrowhead pointing from the subclass to the superclass. In the example of bank accounts, we can use generalization to represent different types of accounts such as current accounts, savings accounts, and credit accounts. The Bank Account class serves as the generalized representation of all types of bank accounts, while the subclasses (Current Account, Savings Account, Credit Account) represent specialized versions that inherit and extend the functionality of the base class. 4. Relationship among classes 4. Relationship among classes 6. Dependency Relationship A dependency exists between two classes when one class relies on another, but the relationship is not as strong as association or inheritance. It represents a more loosely coupled connection between classes. Dependencies are often depicted as a dashed arrow. Let’s consider a scenario where a Person depends on a Book. Person Class: Represents an individual who reads a book. The Person class depends on the Book class to access and read the content. Book Class: Represents a book that contains content to be read by a person. The Book class is independent and can exist without the Person class. The Person class depends on the Book class because it requires access to a book to read its content. However, the 4. Relationship among classes 5. Interplay of Classes and Object In Object-Oriented Analysis and Design (OOAD), the interplay of classes and objects is fundamental to modeling and designing systems. Here's how they interact: 1. Classes: A class is a blueprint or template for creating objects. It defines the properties (attributes) and behaviors (methods or functions) that its objects will have. 2. Objects: An object is an instance of a class. It is a real- world entity that contains data (attributes) and can perform tasks (methods). 5. Interplay of Classes and Object Example: Python Code class Car: def __init__(self, color, speed): self.color = color self.speed = speed
def accelerate(self): self.speed += 10
def brake(self): self.speed -= 10
# Create objects (instances of the Car class)
my_car = Car("red", 0) your_car = Car("blue", 10)
# Objects can call methods
my_car.accelerate() print(my_car.speed) # Output: 10 5. Interplay of Classes and Object Here: Car is the class, defining the structure. my_car and your_car are objects, instances of that class. Methods like accelerate() can modify the state of the objects (like changing their speed). This relationship allows OOAD to model complex systems with real-world analogies, where objects represent real-world entities and interact based on their defined behaviors. 6. Building quality Classes and Object
Building quality classes and objects in Object
Oriented Analysis and Design (OOAD) involves focusing on key principles like abstraction, encapsulation, inheritance, and polymorphism, ensuring each class has a well-defined responsibility, minimal coupling with other classes, and high cohesion within itself, effectively representing real-world entities and their behaviors with appropriate attributes and methods. 6. Building quality Classes and Object
Key aspects of building quality classes and objects:
1. Abstraction: Identify essential features of a real-world entity and model them in the class, hiding unnecessary details. Use methods to encapsulate complex operations, presenting a simplified interface to users. 2. Encapsulation: Bundle data (attributes) and methods together within a class, controlling access to internal state through well-defined methods. Protect sensitive data by using access modifiers (public, private, protected). 6. Building quality Classes and Object
Key aspects of building quality classes and objects:
3. Inheritance: Create a hierarchy of classes where new classes (derived classes) inherit properties and behaviors from existing ones (base classes), promoting code reuse. Use inheritance to model "is-a" relationships between entities. 4. Polymorphism: Allow objects of different classes to be treated as the same type when necessary, enabling flexibility in code design. Achieve polymorphism through method overloading and overriding. 6. Building quality Classes and Object
How to design quality classes and objects:
Step-1: Identify relevant entities: Analyze the problem domain to identify key objects and their relationships. Step-2: Define attributes and methods: For each class, determine the necessary data (attributes) and operations (methods) that represent its behavior. Step-3: Consider relationships: Identify how classes interact with each other using associations (has-a), aggregation (part-of), and composition (stronger form of "has-a"). 6. Building quality Classes and Object
How to design quality classes and objects:
Step-4: Apply abstraction and encapsulation: Hide internal implementation details and provide a well- defined public interface. Step-5: Use inheritance appropriately: Leverage inheritance to create class hierarchies where applicable, ensuring proper "is-a" relationships. Step-6: Review and refine: Continuously evaluate the design for clarity, maintainability, and adherence to good OO principles. Example: Designing a "Customer" class in an online store: Attributes: name, email, address, phone number, order history Methods: addAddress, updateEmail, placeOrder, viewOrderHistory 7. Classification In Object-Oriented Analysis and Design (OOAD), "classification" refers to the process of identifying and grouping similar objects into classes based on their shared attributes and behaviors, essentially allowing developers to organize complex systems by recognizing commonalities and creating reusable components; it's a crucial step in OOAD as it enables the creation of hierarchical relationships between classes through generalization, specialization, and aggregation, leading to more modular, maintainable, and understandable software designs. 7. Classification Key points about classification in OOAD: 1. Identifying classes: The primary function of classification is to identify the different "classes" within a system by analyzing the problem domain and recognizing entities that share similar characteristics. 2. Hierarchical relationships: Classification allows for the creation of hierarchical structures between classes using concepts like generalization (identifying a broader category), specialization (creating more specific subcategories), and aggregation (composing objects from other objects). 7. Classification Example of Classification in a Library System: Step-1 : Identifying Classes: Book: A Book represents a book in the library system. Member: A Member represents a user of the library. Loan: A Loan represents the borrowing of a book by a member. Librarian: A Librarian manages the library. 7. Classification Example of Classification in a Library System: Step-2: Defining Attributes and Behaviors: Book Class: Attributes: title, author, ISBN Behaviors: checkAvailability(), checkOut(), checkIn() Member Class: Attributes: name, memberID, address Behaviors: borrowBook(), returnBook(), payFines() Loan Class: Attributes: loanDate, dueDate, book Behaviors: extendLoan(), calculateFine() Librarian Class: Attributes: name, employeeID,address Behaviors: issueBook(), acceptReturnedBook(), registerMember() 7. Classification Example of Classification in a Library System: Step-3: Generalization and Specialization: A Person class might be created as a generalization of both the Member and Librarian classes, since both have common attributes like name and address. FictionBook and NonFictionBook could be subclasses of the Book class, specializing different types of books with additional behaviors or attributes (e.g., genre for FictionBook). 7. Classification Example of Classification in a Library System: Step-4: Class Relationships: Association: Member and Book have an association through the Loan class (a member borrows a book). Aggregation: The Library might contain Books, but if the library is destroyed, the books are not destroyed. Composition: A Library contains many Books, and if the Library is destroyed, the books also cease to exist within that library. Step-5: Final Class Diagram: The classification process will result in a class diagram, showing how all the identified classes interact, their responsibilities, and their relationships. 8. Importance of Classification 1. Improved understanding: By organizing objects into classes, developers gain a better understanding of the system's structure and relationships between different components. 2. Simplified design process: Classification helps identify the essential elements of a system, making the design process more streamlined and efficient. 3. Enhanced maintainability: Well-defined classes with clear responsibilities are easier to modify and update without causing unintended side effects. 4. Code reusability: By creating reusable classes, developers can reduce development time and improve code quality. 9. Key Abstraction and Mechanism In Object-Oriented Analysis and Design (OOAD), abstraction and mechanism are key concepts that guide the development of object-oriented systems. 1. Abstraction Abstraction refers to the process of simplifying complex systems by focusing on the essential characteristics while hiding the unnecessary details. It allows you to model real- world entities and their relationships without getting bogged down by implementation specifics. In OOAD: This is achieved by defining objects in terms of their properties (attributes) and behaviors (methods) without revealing the internal workings. The goal is to only show the relevant details to the user or other objects. Example: In a banking system, an Account object might have methods like deposit() and withdraw(), but it won't expose the underlying logic of how transactions are processed—just the interface to interact with the object. 9. Key Abstraction and Mechanism Abstraction in OOAD is typically represented in two ways: Data Abstraction: Only essential data is visible to the user, while implementation details are hidden. Control Abstraction: The user interacts with an abstract view of how the system operates, without needing to know the details of control flow or execution. 9. Key Abstraction and Mechanism 2. Mechanism A mechanism is a way in which an abstraction is implemented in an object-oriented system. It's the underlying process or structure that makes an abstraction work. In OOAD: Mechanisms define how certain features of an object are realized. For instance, a mechanism can be the specific algorithms, data structures, or system components that make an object's behaviors and attributes functional. Example: In a game, the Player object may have a method like move(). The mechanism behind the move could be based on physics (calculating the movement using speed, direction, and time), which is hidden behind the abstraction of the move() method. Mechanisms allow for flexibility and extensibility, as they define the implementation but can change without affecting the abstraction. 9. Key Abstraction and Mechanism Relationship between Abstraction and Mechanism: Abstraction focuses on what an object or system does (its interface), while mechanism focuses on how it does it (its implementation). For example, in a class, the abstraction could be the public methods you provide to interact with the class, and the mechanism could be the private methods and data structures that perform the actual work. 9. Key Abstraction and Mechanism Example Breakdown: System: Online shopping platform Key Abstractions: Product: Represents an individual item available for purchase (with attributes like name, price, description, quantity). Customer: Represents a user who can place orders (with attributes like name, address, email). Order: Represents a collection of products purchased by a customer in a single transaction (with attributes like total price, delivery address). 9. Key Abstraction and Mechanism Example Breakdown: System: Online shopping platform Mechanisms: "Add to Cart" functionality: A method within the "Product" class that allows a "Customer" object to add a product to their "ShoppingCart" (another potential abstraction). "Place Order" functionality: A method within the "Customer" class that creates a new "Order" object, associates it with the customer, and populates it with items from the "ShoppingCart". "Payment Processing": A mechanism that might involve interaction between the "Order" object, a "Payment Gateway" class, and the "Customer" object to handle payment details. Questions from Unit-2 1. Explain nature of an object and Relationships among objects. 2. Explain nature of a class and Relationships among classes. 3. Give an example of Interplay of Classes and Object. 4. Discuss Key aspects of building quality classes and objects. 5. Explain classification in OOAD. 6. Write importance of Classification. 7. Explain Key Abstraction and Mechanism in detail. Thank You