Object-oriented analysis looks at a problem as a set of objects that interact, rather than as a set of functions. It is the first step of object-oriented development.
Basic Ideas
An object is something in the problem domain that has identity, state and behaviour, such as a student or an invoice. A class is a group of objects that have the same attributes and operations. Encapsulation binds data and operations in one unit and hides the inside. Inheritance lets a class take the properties of another class. Polymorphism lets the same operation work differently for different classes. Association and aggregation show the relations between objects.
Definition: Object-oriented analysis. A method of analysing a problem by finding the objects and classes of the problem domain and the relations and interactions among them.
Steps of Object-Oriented Analysis
First, the analyst finds the classes from the nouns in the problem statement. Second, the attributes and operations of each class are listed, from the descriptive words and the verbs. Third, the relationships such as association, aggregation and inheritance are drawn in a class diagram. Fourth, the behaviour of the system is shown by use cases, sequence diagrams and state diagrams. The result is a model in the language of the user, which is kept for design and not changed into a design.
Comparison with Structured Analysis
The structured approach separates data and functions, and the system is organised around the functions. The object-oriented approach joins data and functions in objects, and the system is organised around objects. It gives better reuse and a closer match to the real world, so that changes are easier. The structured approach is simpler and suits small and function-oriented problems.
Object-oriented analysis is normally done with the help of use cases. A use case describes a sequence of actions that give a result of value to an actor, such as a student who issues a book. The analyst writes the main course of the use case and its alternatives, and then finds the objects that take part. CRC cards, with the class name, its responsibilities and its collaborators written on a small card, are a simple technique for a team to find classes by role playing. The model is checked by walking through the use cases and seeing that each can be carried out by the classes.
Table 2.4: Structured and object-oriented analysis
| Aspect | Structured | Object-oriented |
|---|---|---|
| Basis | Functions and data flow | Objects and classes |
| Main tools | DFD, data dictionary | Class and use case diagrams |
| Data and functions | Kept separate | Joined in objects |
| Reuse | Low | High |
| Change | Affects many functions | Localised in classes |
Example 2.4: Finding classes
Problem: From the statement "A student enrols in courses, and a teacher teaches courses", find the classes, one attribute each and the relations.
Solution:
- The nouns give classes Student, Course and Teacher.
- Attributes: Student has roll number, Course has code, Teacher has name.
- Student is associated with Course (enrols), and Teacher is associated with Course (teaches).
Result: Three classes with two associations, as in the figure.
Common mistakes
- Making every noun a class. Some nouns are only attributes.
- Putting design details, such as database tables, into the analysis model.
- Forgetting the relationships among classes.
Key takeaways
- An object has identity, state and behaviour.
- Classes are found from the nouns of the problem statement.
- Inheritance, encapsulation and polymorphism are the basic ideas.
- Object-oriented analysis gives better reuse than structured analysis.
Practice questions
- What is a class?
- How are candidate classes found?
- Give one difference between structured and object-oriented analysis.
Answers to the practice questions
- A group of objects with the same attributes and operations.
- From the nouns in the problem statement.
- Structured separates data and functions, object-oriented joins them in objects.
Sources
- Official BCA syllabus Advanced Software Engineering, course code 25BCA405DS01, Unit II
