Object-Oriented Analysis and Design (Part 3)
Object-Oriented Analysis and Design (Part 3)
In part 3 of 4, we look at putting the concepts of Object-Oriented Analysis and Design that we've already discussed into practice.
Join the DZone community and get the full member experience.Join For Free
The Agile Zone is brought to you in partnership with Techtown Training. Learn how DevOps and SAFe® can be used either separately or in unison as a way to make your organization more efficient, more effective, and more successful in our SAFe® vs DevOps eBook.
Example of Object-Oriented Analysis and Design
Here is an example which depicts a simple process for object-oriented analysis and design.
First, I will share a user story that we will tackle in this example:
- A customer arrives at checkout with items to purchase.
- The shopkeeper at the counter greets them and starts a new sale.
- The shopkeeper enters all the items.
- The system calculates the order total and taxes.
- The customer pays.
- The system printed the receipt and updates the inventory.
Steps for Object-Oriented Analysis
There are three steps in the following order:
- Identify class names.
- Identify attributes.
- Identify associations.
Now I suggest that you underline all the nouns in the text of the user story which you think will be good candidates for class names in our code.
Here are all the names of the classes that I can think of by reading the user story above:
You can see in the diagram that it is not developed using any UML tool. I just used a pen and a rough sheet of paper. More than 60 percent of my designing is done on either paper or a whiteboard.
Next steps: identifying attributes and associations. An attribute is what defines a class or object. An attribute can be an Id, amount, or anything that can be measured. The association defines a relationship between classes and objects about how a class is connected to another class.
The following diagram shows the attributes and associations for the class diagram that I have shown above:
Steps in Object-Oriented Design
After the analysis, we moved to object-oriented design. Here are the steps:
- Draw sequence diagram(s) for each scenario.
- Draw a design class diagram.
- Apply design principles and software design patterns.
A sequence diagram is used to show the message passing between objects of classes. It is the most important tool in object oriented design since it helps in designing the behavior of objects involved in a software.
Here is the sequence diagram that I drew to address the user story:
This sequence diagram shows the messages and the ordering in which they are sent among the objects to complete the objective of a user story.
From the sequence diagram, we can easily come up with a design class diagram. A design class diagram is the last artifact that I usually create before diving into code.
It is very easy to draw a design class diagram from the sequence diagram. Just write down the method names in the classes where the arrow is pointing. For example, the
GetItem() message is going from the
Sale Class to the
Item Class. Therefore, the
item class will contain the
After creating the design class diagram, we can apply the principles of object-oriented design and design patterns, but I will put up another post for applying design patterns and principles.
From here, we can move to coding and start coding.
This is a very simple example to depict the process. For a real-life and real-world example of object-oriented analysis and design, you can check out this link.
Summary Up to Now
Up to now, you have learned about the software development process, the software development methodology, the differences between them, and why object-oriented analysis and design are more important than object oriented programming. You learned steps, techniques, and the purpose for object-oriented analysis and object-oriented design.
You also learned from a simple example how you can start properly designing the software using basic but important principles and techniques.
You have learned the technical part. Is that enough?
Will you convince your less-technical (or non-technical) boss to give you time and other resources to apply these activities? This is because these principles will not produce lines of code. And do not produce any functionality for an end-customer demo.
In last part (part 4), I will discuss how can you persuade your boss to let you perform these activities. In addition to this, I will also bust some other myths about object-oriented design.
Published at DZone with permission of Muhammad Umair . See the original article here.
Opinions expressed by DZone contributors are their own.