Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Object-Oriented Analysis and Design (Part 3)

DZone's Guide to

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.

· Agile Zone
Free Resource

See how three solutions work together to help your teams have the tools they need to deliver quality software quickly. Brought to you in partnership with CA Technologies

Introduction

Welcome to part three of a four-part series. Okay, enough of learning principles and theory in part one and part two. Let's apply them here using a very simple example.

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:

user requirements


User Story

  • 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:

Domain Model

UML Domain Model


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:

UML Domain Model with attributes and associations


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:

UML Seqence Diagram

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 GetItem() method.

UML Design Class Diagram


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.

What Next?

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.

Discover how TDM Is Essential To Achieving Quality At Speed For Agile, DevOps, And Continuous Delivery. Brought to you in partnership with CA Technologies

Topics:
agile ,object-oriented programming ,object-oriented-design

Published at DZone with permission of Muhammad Umair. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}