Identifying Objects and their Relationships
Identifying objects and their relationships is a crucial part of object-oriented analysis and design. Here are some general steps that can guide you through this process:
Identify the Problem Domain: Understand the problem that your software is supposed to solve. This can be a business process, a scientific application, a simulation, or any problem that requires a software solution.
Identify Nouns and Verbs: Read through the requirements and specifications documents and identify the nouns and verbs. Nouns usually represent potential classes or objects, while verbs often indicate possible methods or responsibilities of a class.
Identify Classes: From the list of nouns, identify potential classes. A class is a blueprint for creating objects. It's important to differentiate between classes and instances of classes (objects). For example, in a school system, 'Student' would be a class, while 'John Doe', an individual student, would be an instance of the 'Student' class.
Identify Class Attributes: Attributes represent the state or characteristics of a class. For example, a 'Student' class may have attributes such as 'Name', 'Age', 'Grade', 'EnrolledCourses', etc.
Identify Class Methods: Methods represent the behavior of a class. They are actions that an object can perform or actions that can be performed on the object. For example, a 'Student' class may have methods like 'EnrollCourse()', 'DropCourse()', 'CalculateGPA()', etc.
Identify Relationships: Identify the relationships between different classes. The main types of relationships in OOP are Association, Aggregation, Composition, and Inheritance.
Association: This is a simple relationship between two classes, often bi-directional. For example, a 'Teacher' class and a 'Student' class could have an association relationship, as a teacher teaches students, and students learn from a teacher.
Aggregation: This represents a "has-a" relationship but with a weaker relationship. The child can exist independently of the parent. For instance, a 'Classroom' may contain 'Students', but 'Students' can exist without the 'Classroom'.
Composition: This is a strong "has-a" relationship, where the child cannot exist independently of the parent. If the parent is destroyed, so is the child. For example, a 'Question' is part of a 'Test' - if the test is deleted, it doesn't make sense for the question to exist independently.
Inheritance: This represents an "is-a" relationship, for instance, a 'MathTeacher' is a 'Teacher'.
Create a Class Diagram: Finally, represent your classes, their attributes, methods, and relationships in a class diagram. This provides a visual overview of the system's structure and makes it easier to spot potential issues.
Remember that these steps are iterative - as you understand the problem better, you might need to revisit and revise your classes and their relationships.
COSC-1437 / ITSE-2457 Computer Science Dept. - Author: Dr. Kevin Roark