Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 26

Class Diagram

• A class diagram is a static model that shows the classes and the
relationships among classes that remain constant in the system over
time. The class diagram depicts classes, which include both behaviors
and states, with the relationships between the classes. The following
sections present the elements of the class diagram, different
approaches that can be used to simplify a class diagram, and an
alternative structure diagram: the object diagram.
• One of the primary purposes of the structural model is to create a
vocabulary that can be used by the analyst and the users.
• Structural models represent the things, ideas, or concepts—that is,
the objects—contained in the domain of the problem
.
Several categories of objects have been found to help the analyst in creating the list, such as physical or
tangible things, incidents, roles, and interactions.
• Analysts should first look for physical, or tangible, things in the business domain. These could include
books, desks, chairs, and office equipment. Normally, these types of objects are the easiest to identify.

Incidents are events that occur in the business domain, such as meetings, flights, performances, or
accidents.
Reviewing the use cases can readily identify the roles that the people play in the problem, such as
doctor, nurse, patient, or receptionist.
Typically, an interaction is a transaction that takes place in the business domain, such as a sales
transaction.

Other types of objects that can be identified include places, containers, organizations, business records,
catalogs, and policies.
In rare cases, processes themselves may need information stored about them. In these cases processes
may need an object, in addition to a use case, to represent them. Finally, there are libraries of reusable
objects that have been created for different business domains. For example, with regard to the
appointment problem, the Common Open Source Medical Objects could be useful to investigate for
5

potential objects that should be included


Attributes
• Attributes are properties of the class about which we want to capture
information
• Example : Participant class
• lastname, firstname, address, phone, and birthdate
• Access Specifier
Operations
• Operations are actions or functions that a class can perform.
• There are four kinds of operations that a class can contain: constructor, query, update,
and destructor.
• A constructor operation creates a new instance of a class. For example, the patient class may have a method
called insert (), which creates a new patient instance as patients are entered into the system.
• A query operation makes information about the state of an object available to other objects, but it does not
alter the object in any way. For instance, the calculate last visit () operation that determines when a patient
last visited the doctor’s office will result in the object’s being accessed by the system, but it will not make any
change to its information
• An update operation changes the value of some or all the object’s attributes, which may result in a change in
the object’s state. Consider changing the status of a patient from new to current with a method called change
status() or associating a patient with a particular appointment with make appointment (appointment).
• A destructor operation simply deletes or removes the object from the system. For example, if an employee
object no longer represents an actual employee associated with the firm, the employee could need to be
removed from the employee database, and a destructor
Relationships
Relationships (Multiplicity)

Relationships also have multiplicity,


which documents how an instance of an object
can be associated with other instances.
Multiplicity
Generalization and Association
Aggregation
Aggregation is used to portray logical a-part-of relationships and is depicted on a UML class diagram by a
hollow or white diamond. For example in Figure 5-13, three logical aggregations are shown. Logical implies that
it is possible for a part to be associated with multiple wholes or that is relatively simple for the part to be
removed from
Classes—What They Do and How to Find Them
• Classes are the vocabulary and terminology of an area of knowledge.
• As you talk with clients, analyze their area of knowledge, and design
computer systems that solve problems in that area, you learn the terminology
and model the terms as classes in the UML.
• In your conversations with clients, be alert to the nouns they use to describe
the entities in their business. Those nouns will become the classes in your
model.
• Be alert also to the verbs that you hear because these will constitute the
operations in those classes. The attributes will emerge as nouns related to the
class nouns.
you have a core list of classes, question the clients ask to coach what each class is supposed to do within the business.
Their answers will tell you the class responsibilities.
Suppose you’re an analyst building a model of the game of basketball, and you’re interviewing a coach in order to
understand the game. The conversation might go something like this:
Analyst: “Coach, what’s basketball all about?”
Coach: “The goal of the game is to shoot the ball through the basket and score more points than your opponent. Each
team consists of five players: two guards, two forwards, and a center. Each team advances the ball toward the basket
with the objective of ultimately shooting the ball through the basket.”
Analyst: “How does it advance the ball?”
Coach: “By dribbling and passing. But the team has to take a shot at the basket before the shot clock expires.”
Analyst: “Shot clock?”
Coach: “Yes. That’s 24 seconds in the pros, 30 seconds in international play, and 35 seconds in college to take a shot
after a team gets possession of the ball.”
Analyst: “How does the scoring work?”
Coach: “Each basket counts two points, unless the shot is from behind the threepoint line. In that case, it’s three
points. A free throw counts one point. A free throw, by the way, is the penalty a team pays for committing a foul. If a
player fouls an opponent, play stops and the opponent gets to shoot at the basket from the free-throw line.”
Analyst: “Tell me a little more about what each player does.”
Coach: “The guards generally do most of the dribbling and passing. They’re
typically shorter than the forwards, and the forwards are usually shorter than the
center. All the players are supposed to be able to dribble, pass, shoot, and
rebound. The forwards do most of the rebounding and intermediate-range
shooting, while the center stays near the basket and shoots from close range.”
Analyst: “How about the dimensions of the court? And by the way, how long
does a game last?”
Coach: “In international play, the court is 28 meters long by 15 meters wide. The
basket is 10 feet off the ground. In the pros, a game lasts 48 minutes, divided into
four 12-minute quarters. In college and international play, it’s 40 minutes divided
into two 20-minute halves. A game clock keeps track of the time remaining.”
This could go on and on, but let’s stop and take stock of where we are. Here are the nouns you’ve
uncovered:
ball, basket, team, players, guards, forwards, center, shot, shot clock, three-point line, free throw, foul,
free-throw line, court, and game clock.
Here are the verbs:
shoot, advance, dribble, pass, foul, and rebound.
You also have some additional information about some of the nouns—like the relative heights of the
players at each position, the dimensions of the court, the total amount of time on a shot clock, and the
duration of a game.
Finally, your own commonsense knowledge could come into play as you generate a few attributes on your
own. You know, for example, that the ball has attributes like volume and diameter.
Using this information, you can create a diagram like the one in Figure 3.15. It shows the classes, and
provides some attributes, operations, and constraints. The diagram also shows responsibilities. You could
use this diagram as a foundation for further conversations with the coach, to uncover more information.
Practice
• A house may have any number of pets living in it
• The two possible types of pets that can live in a house are dogs and
cats
• Each dog or cat has a name
• An animal’s house is its one and only home
• You can ell an animal to make noise and it will do its thing

You might also like