Konsep SQ 2
Konsep SQ 2
Fundamentals
Chapter Twelve
Learning Objectives
After reading this chapter, you should be able to:
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
366 PART 5 ■ Advanced Design and Deployment Concepts
Bill Santora, the project leader responsible for devel- convincing everybody that the project schedule wasn’t
oping an integrated customer account system at New too risky. The upside is that because each iteration is
Capital Bank, just met with the review committee and only four weeks long, we have something to show right
finished a technical review of the new system’s first-cut at the beginning. You don’t know how relieved I am that
design. This first-cut design focused on four fundamen- the design passed the review! The team has done a
tal core use cases and would be implemented in the first lot of work to make sure the design is solid, and we all
development iteration. felt confident.”
New Capital Bank had been using object-oriented “Well, building it incrementally makes a lot of sense
techniques for quite a while, but it had been slower to and certainly seems to be working,” Mary said. “I espe-
adopt some of the newer Agile approaches. Bill had cially liked the diagrams you showed. It was terrific how
been involved in some pilot projects that had used Uni- the three-layer architectural design supported each use
fied Modeling Language (UML) to develop systems case. Even though I don’t consider myself an advanced
using object-oriented techniques. However, this devel- object-oriented technician, I could understand how the
opment project was his first large-scale project that object-oriented design fit into the architecture. I think
would be entirely Agile. you wowed everybody when you demonstrated how
As Bill was collecting his presentation materials, his you could use the same basic design to support both
supervisor, Mary Garcia, spoke to him: “Your technical our internal bank tellers and a Web portal for our cus-
review went very well, Bill,” she said. “The committee tomers. Congratulations.”
found only a few minor items that need to be fixed. And Bill picked up on Mary’s enthusiasm.
even though I am not completely current on the new “How about the design class diagrams?” he asked.
approach, it was easy for me to understand how these “Don’t they give a nice overview of the classes and the
core functions will work. I still find it hard to believe that methods? We use them extensively as a focus for dis-
you will have these four pieces implemented in the next cussion on the team. They really help the programmers
few weeks though.” write good, solid code.”
“Wait a minute,” Bill said, laughing. “It won’t Mary nodded in agreement and added, “By the
be ready for the users then. Getting these four core way, have you scheduled a review with the users?”
functions coded and running doesn’t mean that we Mary asked.
are almost done. This project will still take a year to “No, not yet,” Bill replied. “The architectural design is
complete.” mostly technical stuff, and we aren’t quite ready to meet
“Yes, I know,” Mary said. “But it is nice that we will with the users. The users will help us by verifying our
have something to show after only one month. Not only understanding of the information availability, but much of
do I feel more confident in this project, but the users what we do now is too technical for them to follow.”
love to see things developing.” “I am excited to see the first pieces run,” Mary said.
“I know,” Bill said. “Remember how much grief “It just makes so much sense to be able to test these
I got when I originally laid out this plan based on an core functions during the rest of the project. Let me
iterative approach? It was difficult to detail the project congratulate you again.” Then, they headed off to lunch
schedule for the later iterations, so I had a hard time together.
■■ Overview
In Chapters 3, 4, and 5, you learned how to do object-oriented analysis by devel-
oping functional requirements models. You learned that analysis consists of two
parts: discovery and understanding. Discovery is learning exactly how the user
conducts his activities through probing questions that provide detailed informa-
tion. Understanding is taking the information gleaned from user interviews and
constructing a set of interrelated and comprehensive models. Model building is
an essential part of understanding the user needs and how they influence the
proposed system. However, the objective of analysis models isn’t to describe the
new system, but to understand, in precise terms, the requirements.
In Chapters 6 and 7, you learned about the need and importance of tech-
nology architecture and application software architecture. Chapter 7 distin-
guished the difference between large software components, such as systems or
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 367
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
368 PART 5 ■ Advanced Design and Deployment Concepts
© Cengage Learning ®
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 369
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
370 PART 5 ■ Advanced Design and Deployment Concepts
//constructors
public Student (String inFirstName, String inLastName, String inStreet,
String inCity, String inState, String inZip, Date inDate)
{
firstName = inFirstName;
lastName = inLastName;
...
}
public Student (int inStudentID)
{
//read database to get values
}
//processing methods
public void updateGPA ( )
{
//access course records and update lastActiveSemester and
//to-date credits and GPA
}
}
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 371
'attributes
Private studentID As Integer
Private firstName As String
Private lastName As String
Private street As String
Private city As String
Private state As String
Private zipCode As String
Private dateAdmitted As Date
Private numberCredits As Single
Private lastActiveSemester As String
Private lastActiveSemesterGPA As Single
Private gradePointAverage As Single
Private major As String
'constructor methods
Public Sub New(ByVal inFirstName As String, ByVal inLastName As String,
ByVal inStreet As String, ByVal inCity As String, ByVal inState As String,
ByVal inZip As String, ByVal inDate As Date)
firstName = inFirstName
lastName = inLastName
...
End Sub
'Processing Methods
Public Function UpdateGPA()
'read the database and update last semester
'and to date credits and GPA
End Function
End Class
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
372 PART 5 ■ Advanced Design and Deployment Concepts
Object-oriented
program classes
Use case Communication with methods
descriptions diagrams
Figure 12-4 Student class example with domain class and design class
Student Student
+getMajor ( ): string
+getCreditHours ( ): number
+updateCreditHours ( )
+findAboveHours (int hours): studentArray
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 373
:StudentUpdController :Student
Actor
changeName (name)
© Cengage Learning ®
nameUpdate
CRC cards are not standard UML, but are very popular for designing simple
systems. This section introduces you to all three.
You first learned about sequence diagrams in Chapter 5 when you learned
about system sequence diagrams (SSD). An SSD only had two actors, the external
actor and the system. A sequence diagram expands the system object to identify
the internal interacting objects. Figure 12-5 illustrates a simple sequence diagram.
Notice that the: System object is no longer included, but two of the internal objects
are shown. Also notice the message arrows between the interacting objects.
A communication diagram is similar to a sequence diagram and serves the
same purpose. Some developers prefer sequence diagrams, whereas others prefer
communication diagrams. Each provides basically the same information, but in
different formats. Each also has strengths and weaknesses. Figure 12-6 illus-
trates a communication diagram for the same use case as Figure 12-5, updating
student name. Chapter 13 elaborates the details and benefits of both sequence
and communication diagrams.
The third model that is used to do detailed object-oriented design and to
provide information for the design class diagram is CRC cards. Even though
the CRC card method is not a standard UML diagraming approach, it provides
a straightforward approach for detailed object-oriented design, especially for
simple use cases, and thus has become popular. (Remember that object-oriented
design is use-case-driven—design is done use case by use case.)
CRC cards include a set of cards, with each card representing a class. Developers
use 3 x 5 cards or some other method to document each card. Each card identifies
the class, its responsibilities (i.e., its methods), and the other classes with which it
collaborates. Figure 12-7 shows both front and back sides of one single CRC card.
The card represents a class. The list on the left is the “responsibilities.” The list on
the front right is the other classes with which this class must “collaborate.” In a later
section, “Designing with CRC Cards,” you will learn how to use these cards.
: St u de nt U p dCo nt ro l l er :Student
Actor
1.3: nameUpdate
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
374 PART 5 ■ Advanced Design and Deployment Concepts
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 375
First-Cut
Design Class Diagram
• Identify classes
• Elaborate attributes
• Identify navigation
Simple use cases Complex use cases
Moderately
complex use cases
Package Diagrams
require extensive design decisions. The middle path, using communication dia-
grams, can be used for use cases that are more complex. The path on the right,
using sequence diagrams, can be used for any use case, no matter the level of
complexity. No matter which technique is used, detailed design does require a
careful thought process to ensure a solid, well-constructed solution.
In any of the three techniques for modeling, the objective is to identify and
define the methods that are required in each class. The final design class dia-
gram documents these required methods. It should be noted that each use case
will have a separate sequence diagram or communication diagram. Furthermore,
the design class diagram is a growing model because as each use case design is
finished, the new methods are added to the existing design class diagram. It is a
composite model containing the method names for all use cases.
Finally, a package diagram can also be added to divide the classes into
components or subsystems that can be implemented as a unit. Some develop-
ers use package diagrams, but many do not. The following section begins the
detailed discussion about design by going into more depth about the design
class diagram.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
376 PART 5 ■ Advanced Design and Deployment Concepts
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 377
«boundary» «dataAccess»
SalelnputWindow SaleDBReader
Attributes.
visiblity attribute-name: data-type-expression = initial-value {property}
© Cengage Learning ®
Method signatures.
visiblity method-name (parameter-list): return-type-expression
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
378 PART 5 ■ Advanced Design and Deployment Concepts
Figure 12-11 Sale superclass (abstract) with three concrete subclasses showing inheritance
Sale Customer
+confirmEmail (emailAddress)
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 379
of design classes with attributes and methods; it shows how inheritance works
for design classes. Each of the three subclasses inherits all the attributes and
methods of the parent Sale class. Hence, each subclass has a saleID, a saleDate,
and so forth. In this example, each subclass also has additional attributes that
are unique to its own specific class. Each of the subclasses also has a unique
attribute that is underlined, such as noOfPhoneSales. As previously mentioned,
class-level attribute an attribute that underlined attributes are class-level attributes and have the same characteris-
contains the same value for all objects in the tics as class-level methods. A class-level attribute is a static variable, and it con-
system tains the same value in all instantiated objects of the same type.
Not only are methods and attributes inherited by the subclasses, but asso-
ciations are also inherited. In Figure 12-11, the Sale object must be associated
with exactly one customer. Each subclass inherits the same association; it must
be associated with exactly one customer. Finally, notice that the title of the Sale
class is italicized. As defined in Chapter 4, an italicized class name indicates that
it is an abstract class—a class that can never be instantiated. In other words,
there are never any Sale class objects. All orders in the system must be instanti-
ated as one of the three subclasses, which are concrete classes, meaning that
every order in the system will be either a TelephoneSale, an OnlineSale, or an
InStoreSale. The purpose of an abstract class is illustrated by the figure. It pro-
vides a central holding place for all the attributes and methods that each of the
three subclasses will need. This example demonstrates one way that OOP imple-
ments reuse. The methods and attributes in the abstract superclass only need to
be written once in order to be reused by each of the subclasses.
0..* 0..*
InventoryItem Sale
inventoryID {key} SaleItem
size quantity 1 saleID {key}
0..* saleDate
color price
© Cengage Learning ®
1 priorityCode
options backorderStatus 1..* shipping&Handling
quantityOnHand 1 tax
averageCost grandTotal
reorderQuantity
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
380 PART 5 ■ Advanced Design and Deployment Concepts
❚❚ Elaboration of Attributes
The elaboration of the attributes is fairly straightforward. The type information
is determined by the designer, based on his or her expertise. In most instances,
all attributes are kept invisible or private and are indicated with minus signs
before them. We also need to add a new compartment to each class for the addi-
tion of method signatures.
❚❚ Navigation Visibility
As stated earlier, an object-oriented system is a set of interacting objects. The
sequence diagrams document which interactions occur between which objects.
However, for one object to interact with another, the first object must be vis-
navigation visibility a design principle in ible to the second object. In this context, navigation visibility refers to the
which one object has a reference to another ability of one object to interact with and send messages to another object.
object and thus can interact with it S ometimes, developers refer to navigation visibility as just navigation or vis-
ibility. However, using just the term visibility can cause confusion with attri-
bute or method visibility. We will use either the term navigation visibility or
navigation to distinguish the concept from public and private visibility on
attributes and methods.
Figure 12-13 shows one-way navigation visibility between the Customer
class and the Sale class. It is called “one-way” because Customer can interact
with Sale, but Sale does not have a direct reference back to Customer. The navi-
gation arrow indicates that a Sale object must be visible to the Customer object.
Notice the variable called mySale in the Customer class. This variable refers to a
Sale instance. The mySale attribute is included in the example to provide a way
to actually implement it. This is quite different from the database concept of
including a foreign key. The mySale attribute is not the value of the key to a Sale
object, but it is an actual programming reference to the Sale object. You could
even think of it as having a Sale object embedded within the Customer object.
From a database point of view, you would do exactly the reverse. You would put
a foreign key of the Customer in the Sale data record to capture the one-to-many
relationship. (One customer has many sales.)
Now let’s think about adding navigation visibility to the RMO design class
diagram. Remember that you are designing just the first-cut class diagram, so
you might continue to modify the navigation arrows as the design progresses.
-mountainBucks: int
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 381
You should ask the following basic question when building navigation visibil-
ity: Which classes need to have references to or be able to access which other
classes? Here are a few general guidelines:
■■ One-to-many associations that indicate a superior/subordinate relationship are
usually navigated from the superior to the subordinate—for example, from
Sale to SaleItem. Sometimes, these relationships form hierarchies of navigation
chains—for example, from Promotion to ProductItem to InventoryItem.
■■ Mandatory associations, where objects in one class can’t exist without
objects of another class, are usually navigated from the independent class to
the dependent class—for example, from Customer to Sale.
■■ When an object needs information from another object, a navigation arrow
might be required, pointing either to the object itself or to its parent in a
hierarchy.
■■ Navigation visibility arrows may be bidirectional—for example, a Sale
object might need to send a message to its Customer object as well as
the reverse.
The very first step you do when creating the first-cut design class diagram
is to add a controller class. You will learn more about controller classes in the
next chapter. Basically, the controller class is a switchboard between the input
screens and the programming logic classes, i.e. the domain classes, for a par-
ticular use case. In our examples, we will always create a controller class for
each use case, and place it between the user-interface classes and the problem
domain classes.
Figure 12-14 is a first-cut design class diagram for the use case Create tele-
phone sale based on the steps described earlier: add a controller class, elaborate
attributes, and identify navigation visibility. To elaborate the attributes, you add
type information and visibility. To add navigation visibility, you first identify
which classes may be involved and then determine the classes that require navi-
gation visibility to other classes. For example, for the Create telephone sale use
case, price information is in the PromoOffering class and description informa-
tion is in the ProductItem class. In most instances, it is unnecessary to put the
navigation visibility reference attribute in the class. (And, in fact, there are some
languages that do not require it.) In other words, the mySale attribute is redun-
dant to the information provided by the arrow. So, even though it was shown
in Figure 12-13 to emphasize the concept of navigation visibility, it is left off in
Figure 12-14 and subsequent figures.
As a reminder, one thing to remember about navigation visibility is that the
classes are programming classes, not database classes. So, we aren’t thinking
about foreign keys in a relational database. We are thinking about object refer-
ences in a programming language.
Figure 12-14 includes SaleHandler as the controller class. As mentioned pre-
viously, a controller class, or use case controller, is a utility class that helps in the
processing of a use case. Notice that it has navigation visibility at the top of the
visibility hierarchy and starts the use case by messaging a customer.
Three points are important to note: First, as design proceeds use case by use
case, you need to ensure that the sequence diagrams support and implement the
navigation visibility that was initially defined. Second, the navigation arrows
need to be updated as design progresses to be consistent with the design details.
Finally, method signatures will be added to each class based on the design deci-
sions made when creating the interaction diagrams for the use cases.
As discussed earlier and shown in Figure 12-8, for use cases that are simple,
a developer will often use CRC cards to design the detail flow of execution for
the use case from one class to another. The next section explains how CRC
cards can be used to design a use case.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
382 PART 5 ■ Advanced Design and Deployment Concepts
Figure 12-14 First-cut RMO design class diagram for the Create telephone sale use case
SaleTransaction
«controller»
SaleHandler -transactionID: int {key}
-saleDate: date
-transactionType: string
-amount: currency
-payMethod: string
© Cengage Learning ®
-regularPrice: currency -averageCost: currency
-picture: blob -reorderQuantity: int
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 383
Responsibilities
Customer
accountNo
update name Sale customerName
update address Payment mobilePhone
request purchase history homePhone
status
process sale
© Cengage Learning ®
make payment
activity diagrams, system sequence diagrams, and use case descriptions, should
be provided, along with a stack of blank CRC-formatted index cards.
For each use case that needs to be designed, these steps are repeated:
1. Select a use case. Because the process is to design a single use case, start
with a set of unused CRC cards. The first card to include should be a use
case controller card.
2. Identify the first problem domain class that has responsibility for this use
case. This object will receive the first message from the use case control-
ler. Using the domain model that was developed during analysis, select one
class to take responsibility. Focus only on the problem domain classes. On
the left side of the card, write the object’s responsibility. For example, a
Customer object may take responsibility to make a new sale, so one respon-
sibility may be Create phone sale.
3. Identify other classes that must collaborate with the primary class to com-
plete the use case. In other words, identify the classes that have required
information or that need to be updated in this use case. As you identify a
collaborating class, go to the appropriate CRC card for that class and write
its responsibilities on the cards. Also, on the back of each card, write the
pertinent information about required attributes of each object class.
4. Another helpful step is to include the user-interface classes. If a user is
part of the team and if some preliminary work has been done on the user-
interface requirements, it could be effective to add CRC cards for all user-
interface window classes that are required for the use case. By including
user-interface classes, all the input and output forms can be included in the
design, making it much more complete.
5. Add any other required utility classes that are needed to the solution. For
example, for a three-layer design, data access classes will be part of the
solution. Usually, each persistent domain class will have a data access class
to read and write to the database.
At the end of this process, you will have a small set of CRC cards that col-
laborate to support the use case. This process can be enhanced with several
other activities. First, the CRC cards can be arranged on the table in the order
they are executed or called. In other words, the calling order can be determined
at this time.
To begin, let’s work through a simple use case. Referring back to
Figure 12-8, we first choose a use case. Next, we create the first-cut design class
diagram with navigation. In Chapter 5, we identified a simple use case called
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
384 PART 5 ■ Advanced Design and Deployment Concepts
Address
-accountNo: string {key}
-typeOfAddress: string
-number: string
-street: string
-city: string
-state: string
-postalCode: string
Create customer account. Figure 12-16 is the first-cut design class diagram,
with navigation visibility added. (Remember that this is simply a preliminary
assessment at navigation visibility; it may change as we proceed with the design.)
To create this, we first looked at all those domain classes that had associa-
tion relationships with the Customer class (see Figure 4-24), and selected those
that might be created or updated with this use case. For this use case, we only
selected the Account class and the Address class.
To learn how the CRC cards process works, let’s go through each step
listed above and develop the necessary CRC cards. We will use many other
requirements models that were created in previous chapters for this use case.
In Chapter 5, you saw an activity diagram (refer back to Figure 5-4) and a
system sequence diagram (refer back to Figure 5-10), which document the
results of analysis activities to determine requirements. That information will
also help define the responsibilities of the object classes. So the analysis mod-
els identify what needs to be done, but during design we may make changes
as we implement how to do it. Remember, however, that during design we
may need to make changes based on good design principles and programming
techniques.
1. We have selected the use case Create Customer Account. At this point, we
will call the controller card, CustomerHandler. Figure 12-17 illustrates this
card. The only responsibility that we have identified so far is a method to
create a new Customer object.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 385
2. The primary class responsible for creating a new customer account could
be the Customer class, so we will add a CRC card for Customer. It makes
sense that a Customer class takes responsibility for creating and updat-
ing anything having to do with customer details such as accounts and
addresses. The Customer class also has the responsibility to instantiate a
new object with a constructor method. Some developers like to include
constructor responsibilities, while others do not. In our example, we will
not include the constructor. The programmers will know that every class
requires at least one constructor. The input information for the constructor
can be found in the SSD, as shown in Figure 5-10. Figure 12-18 illustrates
the completion of step 2.
3. For the third step, we observe from Figure 5-4 and Figure 5-10 that there
are two other messages coming into the system. One message passes
address data and another message passes credit card information. Also
note in Figure 12-16 that there are two other classes involved in this use
case, Address and Account. When creating a new customer, the system
also needs to instantiate a new Account object, and at least one new
Address object, though there may also be multiple address objects created.
Figure 12-19 illustrates the completion of step 3, except for the attributes,
which are not being shown in this example.
4. For the fourth step, we will add the user-interface classes. Input to this
design step will come from two sources, the parameters on the messages
as seen in Figure 5-10, and the screen designs and layouts designed during
input design. In this instance, let’s assume that the user requirement is to
have a starting screen that captures basic information such as name, phone
numbers, and e-mail addresses. A second input screen will allow enter-
ing address information, multiple times if necessary. A final input screen
will accept credit card information. Because there may be extra processing
required to verify credit information at that point, the user wanted to have
it on a separate input screen. Figure 12-20 illustrates this step in the CRC
design process.
5. For the fifth and final step, we add three more CRC cards for the data-
base access classes—one for each of Customer, Address, and Account.
Address
CustomerHandler Customer
create Customer Customer create Address Address
create Account Account
Account
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
386 PART 5 ■ Advanced Design and Deployment Concepts
Figure 12-20 CRC cards for Create customer account with input classes identified
CustomerScreen
accept customer info CustomerHandler
Address
CreditcardScreen
accept CC info CustomerHandler
Figure 12-21 CRC cards for Create customer account with DB classes
AddressDB
write Address
CustomerScreen
accept customer info CustomerHandler
Address
AddressDB
CreditcardScreen CustomerDB
write Customer
accept CC info CustomerHandler
AddressDB
write Account
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 387
Figure 12-22 DCD with method signatures added from CRC cards
«controller»
Customer
CustomerHandler
Address Account
and information from the system sequence diagram (SSD). The methods in the
design class diagram are derived from the lists of responsibilities on each card.
In other words, each responsibility should translate to a method. The CRC cards
identify responsibilities, but do not normally include the complete method sig-
natures with parameters and returns. Not having to worry about parameters
simplifies the CRC card process, but it requires that the developer add that
information when the design class diagram is completed. Also, because we have
elected not to include the constructor responsibilities on CRC cards, we have
not included the constructor methods on the final design class diagram. So even
though there are no methods defined for Address or Account, we know that
there are constructor methods that execute when new objects are instantiated. If
we were to define multiple constructor methods with different parameters and
returns, we could add them to this final version of the design class diagram.
Figure 12-22 shows the updated design class diagram of the domain layer with
method signatures added for this use case.
Let’s show one more example. Figure 12-14, which we developed to illus-
trate design class diagram elements, contains the first-cut design class diagram
for the RMO use case Create telephone sale. We will complete this example and
show the set of CRC cards and the final design class diagram.
For this example, it makes sense that the Customer object creates a Sale
object, the Sale object creates SaleItem objects, and SaleItem objects access Pro-
ductItem, InventoryItem, and PromoOffering objects to get required informa-
tion. We had determined this when we created the first-cut design class diagram
in Figure 12-14. Figure 12-23 illustrates a solution set of CRC cards for the use
case Create telephone sale. The process payment responsibility in the Sale class
will cause a SaleTransaction to be created.
To finish the example, let us go back to the design class diagram and update
it based on the design information created during the CRC card brainstorming
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
388 PART 5 ■ Advanced Design and Deployment Concepts
Figure 12-23 CRC cards model for Create telephone sale use case
Sale PromoOffering
add/delete item SaleItem provide price
process payment SaleTransaction
NewSaleWindow
accept input SaleHandler SaleHandler
display results
accept payment start new sale Customer
accept item request Sale SaleItem ProductItem
accept payment
delete item PromoOffering provide description
request backorder ProductItem
Inquire-addItemWindow InventoryItem
SaleTransaction InventoryItem
© Cengage Learning ®
provide quantity
update quantity
order new supply
session. Figure 12-24 shows an updated design class diagram, with methods
navigation visibility updates added. Note that the SaleHandler class needs vis-
ibility to the Sale class to process a payment. Compare the responsibilities iden-
tified on the CRC cards and the method names described in each class. Note the
close correlation. Also remember that we have not included constructors. So for
example, the SaleTransaction has a constructor method, which is not shown, to
process the payment by instantiating a new SaleTransaction object.
Often, when developers begin using CRC cards, they assign many different
responsibilities for a given class. For example, developers might say the SaleItem
class should get the price. In reality, the PromoOffering class provides the price
and the SaleItem only uses it. In other words, it helps to think of responsibili-
ties as being similar to methods—requests to do something rather than random
actions that need to occur.
As method names and navigation visibility are added to the design class
diagram for each use case, the overall diagram grows and becomes the central
repository of all information about every class in the new system. Each set of
CRC cards, or interaction diagrams as shown in the next chapter, can be used
for programming the new system. The overall design class diagram becomes a
source for verification that all use cases have been programmed completely and
accurately.
Now that you have some idea of the design process, let’s go back through
and think about what makes a good design.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 389
© Cengage Learning ®
-picture: blob -reorderQuantity: int
These characteristics determine the quality of the design. In other words, they
indicate the “goodness” of the detailed design and the implementation of the
new system. Although understanding and using the following design principles
will not guarantee a high-quality design, applying these principles will increase
the probability that the design is solid. Ignoring the following principles will
almost certainly ensure a less-than-optimal software design.
The following discussion of good design principles is a launching point for
you to understand how to design high-quality software. However, it is not a
comprehensive discussion. There are many good books and articles on the prin-
ciples of good object-oriented design, which further explain principles and tech-
niques of good design.
■■ Object Responsibility
One of the most fundamental principles of object-oriented design is the idea of
object responsibility a design principle in object responsibility; that is, objects should be responsible for carrying out
which objects are responsible for carrying out system processing. These responsibilities are categorized in two major areas:
system processing knowing and doing. In other words, what is an object expected to know and
what is an object expected to do or to initiate?
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
390 PART 5 ■ Advanced Design and Deployment Concepts
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 391
interface. However, building the system with a use case controller allows the
user interface to simply send all its input messages to the use case controller
class. Thus, changes to the methods or classes in the business logic and domain
layer are isolated to the controller class. You will find that protection from vari-
ations affects almost every design decision, so you should watch for and recog-
nize the application of this principle in all design activities.
■■ Indirection
indirection a design principle in which an Indirection is the principle of separating two classes or other system compo-
intermediate class is placed between two nents by placing an intermediate class between them to serve as a link. In other
classes to decouple them but still link them words, instructions don’t go directly from A to B; they are sent through C first.
Or in message terminology, don’t send a message from A to B. Let A send the
message to C and then let C forward it to B.
Although there are many ways to implement protection from variations,
indirection is frequently used for that purpose. Inserting an intermediate object
allows any variation in one system to be isolated in that intermediate object.
Indirection is also useful for many corporate security systems. For example,
many companies have firewalls and proxy servers that receive and send mes-
sages between an internal network and the Internet. A proxy server appears as a
real server—ready to receive such messages as e-mail and HTML page requests.
However, it is a fake server, which catches all the messages and redistributes
them to the recipients. This indirection step allows security controls to be put in
place and protect the system.
A common example of indirection that we have been using throughout is the
insertion of a use case controller. The controller is a separate class that receives
all the inputs and directs it to the appropriate domain classes.
■■ Coupling
This principle, coupling, and the next principle, cohesion, were originally
defined during the early days of software design and programming. However,
both principles continue to be extremely important and applicable to object-
oriented design.
In the previous examples throughout the text of the RMO class diagram,
you have seen that the Customer class and the Sale class are linked together in
coupling a qualitative measure of how an association relationship. Another term for this linking is coupled. Coupling
closely the classes in a design class diagram is a qualitative measure of how closely the classes in a design class diagram are
are linked linked. A simple way to think about coupling is by the number of association
relationships and whole/part relationships on the design class diagram. Previ-
ously, you learned about navigation visibility, which measures what a class can
link to and access. Low coupling is usually better for a system than high cou-
pling. For example, a Customer object can access a Sale object that belongs to
it. However, if it can also directly access the SaleItem, that would be too much
coupling. Only the Sale object should be able to access its own SaleItem objects.
We say that coupling is a qualitative measure because no specific number
measures coupling in a system. It is a global measure that applies to a set of
classes for a particular use case design. It does not measure an individual class.
A designer must develop a feel for coupling—that is, recognize when there is too
much or too little. Coupling is evaluated as a design progresses—use case by use
case. Generally, if each use case design has a reasonable level of coupling, the
entire system will too.
Refer back to Figure 12-1 to observe the flow of messages between the
objects. Obviously, objects that send messages to each other must have visibility
and thus are coupled. For the Input window object to send a message to the Stu-
dent object, it must have visibility, or be coupled, to it. The Input window object
isn’t connected to the Database access object, so those objects aren’t coupled.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
392 PART 5 ■ Advanced Design and Deployment Concepts
If we designed the system so the Input window object accessed the Database
access object, the overall coupling for this use case would increase; that is, there
would be more connections. Is that good or bad? In this simple example, it
might not be a problem. But for a system with 10 or more classes, too many
connections with visibility can cause high levels of coupling, making the system
more complex and therefore harder to maintain.
So, why is high coupling bad? The main reason is that a change in one class
ripples through the entire system and may cause methods to fail. Therefore,
experienced analysts make every effort to simplify coupling and reduce ripple
effects in the design of a new system.
■■ Cohesion
cohesion a qualitative measure of the Cohesion refers to the consistency of the functions within a single class and is a
focus or unity of purpose within a single class qualitative measure of its focus or unity of purpose. Unlike coupling (where you
want low coupling), classes need to be highly cohesive to be well designed. For
example, in Figure 12-1, you would expect the Student class to have methods—
that is, functions—to enter student information, such as identification number
or name. That would represent a unity of purpose and a highly cohesive class.
But what if that same object also had methods to make classroom assignments
or assign professors to courses? The cohesiveness of the class would be reduced.
Classes with low cohesion have several negative effects. First, they are hard
to maintain. Because they perform many different functions, they tend to be
overly sensitive to changes within the system, suffering from ripple effects.
S econd, it is hard to reuse such classes because they have many different—and
often unrelated—functions. For example, a button class that processes button
clicks can easily be reused. However, a button class that processes both button
clicks and user log-ins has limited reusability. A final drawback is that classes
with low cohesion are usually difficult to understand. Frequently, their func-
tions are intertwined and their logic is complex.
Although there is no firm metric to measure cohesiveness, we can think
about classes as having very low, low, medium, or high cohesion. Remember,
high cohesion is the most desirable. An example of very low cohesion is a class
that has responsibility for services in different functional areas, such as a class
that accesses both the Internet and a database. These two types of activities are
different and accomplish different purposes. To put them together in one class
causes very low cohesion.
An example of low cohesion is a class that has different responsibilities, but
in related functional areas—for example, a class that handles all database access
for every table in the database. It would be better to have different classes to
access customer information, order information, and inventory information.
Although the functions are the same—that is, they access the database—the
types of data passed and retrieved are very different. Thus, a class that is con-
nected to the entire database isn’t as reusable as one that is only connected to the
Customer table.
An example of medium cohesion is a class that has closely related responsi-
bilities, such as a single class that maintains customer information and customer
account information. A better design would be to define two highly cohesive
classes: One class could be defined for customer information, such as names
and addresses, and another class or set of classes could be defined for customer
accounts, such as balances, payments, credit information, and all financial activ-
ity. If the customer information and the account information are limited, they
could be combined into a single class with medium cohesiveness. Either medium
or highly cohesive classes can be acceptable in systems design.
Now let’s begin the detailed design process by investigating the properties
and details of the design class diagram.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 393
Chapter Summary
The ultimate responsibility of system developers is to is refined and expanded as the sequence diagrams are
write computer software that solves a business prob- developed. One method of determining which objects
lem. This chapter focuses on how to configure and collaborate is to use class responsibility collaboration
develop the solution system—that is, how to design (CRC) cards. For simple use cases, a set of CRC cards
the details of the new system. Systems design is the may be sufficient to write code. For more complex use
bridge that puts business requirements in terms that cases, other interaction diagrams are normally used.
the programmers can use to write the software that One reason that we suggest a more formal system
becomes the solution system. of design, rather than just starting to write code is
Using all the requirements models as well as the that the final system is much more robust and main-
architectural design, object-oriented design extends tainable. Design as a rigorous activity builds better
the models so programming can proceed. The objec- systems. Some fundamental principles should be con-
tive of object-oriented design is to determine the sidered as a system is developed; specifically, two criti-
methods within individual classes that are needed to cal ideas are coupling and cohesion. A good system
implement the use cases. The process of design is use- has low coupling between the classes, and each of the
case-driven, in that it is done one use case at a time. classes has high cohesion. Another important principle
The process of object-oriented design can be is “protection from variations,” meaning that some
divided into two major areas: developing a design class parts of the system should be protected from and not
diagram (DCD) and identifying the methods for each tightly coupled to other parts of the system that are
use case via an interaction diagram. The DCD is usu- less stable and subject to change. Being a good devel-
ally developed in two steps. A first-cut DCD is created oper entails learning and following the principles of
based on the domain model class diagram, but then it good design.
Key Terms
boundary or view class data access class object responsibility
class-level attribute entity class persistent class
class-level method indirection protection from variations
cohesion instantiation separation of responsibilities
controller class method signature stereotype
coupling navigation visibility visibility
CRC (class responsibility object-oriented design
collaboration) cards
Review Questions
1. Describe in your own words how an object- 7. What do we mean by use-case-driven design?
oriented program works. 8. Explain in your own words what coupling means
2. What is instantiation? and why it is important.
3. List the models that are used for object-oriented 9. Explain what cohesion means and why it is
systems design. important.
4. Explain how domain classes are different from 10. Compare and contrast the ideas of coupling and
design classes. cohesion.
5. What is the difference between a system sequence 11. What is protection from variations, and why is it
diagram and a sequence diagram? important in detailed design?
6. In your own words, list the flow of steps for doing 12. What is meant by object responsibility, and why is
object-oriented design. it important in detailed design?
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
394 PART 5 ■ Advanced Design and Deployment Concepts
13. What is meant by separation of responsibilities? 18. What information is added to the domain model
14. What are (a) persistent classes, (b) entity classes, to derive the first-cut DCD?
(c) boundary classes, (d) controller classes, and 19. Describe navigation visibility. Why is it important
(e) data access classes? in detailed design?
15. What are class-level methods and class-level 20. List some typical conditions that dictate in which
attributes? direction navigation visibility occurs.
16. What is a method signature? 21. What information is maintained on CRC cards?
17. Compare and contrast abstract and concrete 22. What is the objective of a CRC card design session?
classes. Give an example of each. 23. How are CRC cards used to update the DCD?
Case Study
The State Patrol Ticket-Processing 1. Draw a DCD for the ticket-processing system based
on the four classes just listed and include attributes,
System (Revisited) association, and multiplicity.
In Chapter 3, you identified use cases and considered the 2. List the classes that would be involved in the use
domain classes for the State Patrol ticket-processing sys- cases and decide which class should be responsible
tem. Review the descriptions in that chapter for the use for collaborating with the other classes for the use
case Record a traffic ticket. Recall that the domain classes case Record a t raffic ticket. Consider some possibili-
included Driver, Officer, Ticket, and Court. ties: (1) A Driver object should be responsible for
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 12 ■ Object-Oriented Design: Fundamentals 395
recording his/her ticket, (2) the Officer object should 3. Create a set of CRC cards showing these classes,
be responsible for recording the ticket that he or she responsibilities, and collaborations for the use case.
writes, and (3) a Ticket object should be responsible 4. Draw a DCD based on your CRC cards. Include method
for recording itself. names.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
396 PART 5 ■ Advanced Design and Deployment Concepts
Figure 12-25 Use cases for the patient and physician actors
View/respond View/respond
to alert. to alert.
View history.
Patient Physician
Set alert
Annotate history.
conditions.
© Cengage Learning ®
View/hear View/hear
message from message from
physician. patient.
Further Resource s
Grady Booch, James Rumbaugh, and Ivar Jacobson, Ivar Jacobson, Grady Booch, and James Rumbaugh,
The Unified Modeling Language User Guide. The Unified Software Development Process.
Addison-Wesley, 1999. Addison-Wesley, 1999.
Grady Booch, et al., Object-Oriented Analysis and Philippe Kruchten, The Rational Unified Process, An
Design with Applications (3rd ed.). Addison- Introduction. Addison-Wesley, 2000.
Wesley, 2007. Craig Larman, Applying UML and Patterns: An Intro-
E. Reed Doke, J. W. Satzinger, and S. R. Williams, duction to Object-Oriented Analysis and Design
Object-Oriented Application Development Using and the Unified Process (3rd ed.). Prentice Hall,
Java. Course Technology, 2002. 2004.
E. Reed Doke, J. W. Satzinger, and S. R. Williams, Robert Martin C. Agile Software Development,
Object-Oriented Application Development Using Principles, Patterns, and Practices. Prentice Hall,
Microsoft Visual Basic .NET. Course Technology, 2002.
2003. Jeffrey Putz, Maximizing ASP.NET Real World,
Hans-Erik Eriksson, Magnus Penker, Brian Lyons, and Object-Oriented Development. Addison-Wesley,
David Fado, UML 2 Toolkit. John Wiley & Sons, 2004. 2005.
Martin Fowler, UML Distilled: A Brief Guide to the James Rumbaugh, Ivar Jacobson, and Grady Booch,
Standard Object Modeling Language (3rd ed.). The Unified Modeling Language Reference Manual.
Addison-Wesley, 2004. Addison-Wesley, 1999.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Object-Oriented Design:
Use Case Realization
Chapter Thirteen
Learning Objectives
After reading this chapter, you should be able to:
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
398 PART 5 ■ Advanced Design and Deployment Concepts
The integrated customer account system project for “I really like the approach of first doing a rough de-
New Capital Bank was now two months old. The first sign using CRC cards,” Charlie replied. “It’s nice to have
development iteration had gone pretty well, although a couple of users there with us to verify that our col-
there were a few snags because the team was still learn- laborations are correct. For the simple use cases, we
ing the ins and outs of iterative development projects. can work with the users to lay out the user interface.
Bill Santora, the project leader, was discussing some Between the CRC cards and the user-interface specifi-
of the system’s technical details with Charlie Hensen, cations, we should have enough to program from, espe-
one of his team leaders, in preparation for the iteration cially now that we have the basic structure set up. Then,
retrospective. for the more complex use cases, we can go ahead and
“How is the team feeling about doing detailed do a detailed design with communication diagrams or
d esign?” Bill asked Charlie, who was one of the early sequence diagrams. The nice thing about these interac-
critics of doing more formal design. “I know some of tion diagrams is that they’re detailed enough for us to
the programmers wanted to just start coding from the hand the designs over to some of the junior program-
use case descriptions that were developed with the mers. It makes them much more effective in their team
users. They weren’t very happy about taking the time to contributions.”
design. Is that still a problem?” “So, would you change our approach or do you think
“It really has worked out quite well,” Charlie said. it’s working the right way?” Bill asked, still looking for
“As you know, I was skeptical at first and thought it ways to improve the process.
would waste a lot of time. Instead, it has allowed us to “Well, it really is working pretty well right now,”
work together better because we know what the other Charlie said. “One thing I really like about it is that we
team members are doing. I also think the system is have a common domain class diagram that everyone
much more solid. We’re all using the same approach, and can access and review. That really helps when you’re
we’ve discovered that there are quite a few classes we ready to insert some code into a class to check and see
share. Of course, we don’t waste a lot of time making what is already there. The central repository for all our
fancy drawings. We do document our designs with tem- code and for the diagrams we do formalize is a great
porary drawings, but that is about as far as we take it.” tool. I wonder if there is a way to get more use out of
“What would you say were the strengths and weak- that tool. Other than that, I would say let’s stick with this
nesses of our approach?” Bill asked, “Or are there ways approach for another iteration and see if it needs chang-
you think we could do it better in this next iteration?” ing after that.”
■■ Overview
In Chapter 12, you learned the objective of object-oriented design and the fun-
damental approach. In Figure 12-3, you learned that design includes informa-
tion about the classes and about the processes. In Figure 12-8, you learned the
approach to (1) select a use case, (2) identify the classes involved and begin the
design class diagram, (3) choose a modeling technique to identify the messages
and methods, and (4) finalize the class methods in the design class diagram.
This chapter pursues object-oriented detailed design in more depth and
formality. This chapter focuses on the foundation principles, which are based
on the concepts of use case realization by using UML interaction diagrams
and design patterns. You will learn how to use communication diagrams and
sequence diagrams to extend the input messages and define internal messages.
These techniques will first focus on the problem domain classes and then extend
to multilayer design.
The last section of this chapter is a brief introduction to design patterns.
As with any engineering discipline, certain procedures have become tried and
proven solutions. Even though object-oriented development is a relatively young
engineering discipline, it offers standard ways to design use cases that lead to
solid, well-constructed solutions. You will learn a few of those standard designs
or patterns.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 399
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
400 PART 5 ■ Advanced Design and Deployment Concepts
Figure 13-1 Communication diagrams and sequence diagrams are interaction diagrams
Message
InteractionDiagram
Object
are more detailed and allow the designer to visually document the process flow
of the messages. This chapter begins the discussion with communication dia-
grams and then moves to sequence diagrams. First, the following section briefly
discusses the concept of a use case controller.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 401
good solution. A use case controller is a completely artificial class created by the
person doing the system design. Sometimes, such classes are called artifacts or
artifact objects.
An object that
An actor who sends receives a message
the initial message and sends other
messages
1: firstMessage ( ) 2: secondMessage ( )
:Object :Object2
4: finalResponse ( ) 3: returnMessage ( )
Actor
© Cengage Learning ®
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
402 PART 5 ■ Advanced Design and Deployment Concepts
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 403
Figure 13-3 Communication diagram for Create customer account use case
aAdd:Address
1: createNewCustomer 1.1: aC := createNewCustomer
(name, mobilePh, homePh, email) (name, mobilePh, homePh, email)
asterisk between the number and the name indicates that the message may be
sent multiple times. This is called a multiply occurring message.
The next set of messages, 1.1, 2.1, and 3.1, use the hierarchical dot notation
to indicate that they are part of a sequence. Looking at 1.1, notice that it has a
return value. Also note that the Customer object is named aC:Customer. The
underline indicates an object and not a class. The aC: is the name or identifier for
this particular object. That information (i.e., the name of the object) is returned
to the :CustomerHandler object. Referring back to Figure 12-16, note that the
:CustomerHandler object has navigation visibility to the :Customer object. This
mechanism of returning the identifier of the newly created :Customer object
provides this navigation visibility. Thus, the :CustomerHandler object can pass
the other messages to the correct object because it has a reference to it.
The next set of messages, 2.2 and 3.2, have a similar form. Each sends a
create message to the appropriate object and returns the identifier of the newly
created object. These two messages include the detail parameters to be passed.
In the earlier messages, 2, 2.1, 3, and 3.1 only abbreviated parameter lists were
given. The full parameter list is more correct. The abbreviated lists were used
purely to save space. Remember, the purpose of modeling is to provide guide-
lines for programming. So designers sometimes take liberties with the formality
of the model, as long as it is still understandable.
Finally, it is worth mentioning that some return messages have been left off
from :CustomerHandler to the Clerk. A system will normally return and display
the data that was entered so that the actor can verify that the correct informa-
tion was stored. In Figure 13-2, the method of returning data is indicated with
a return message.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
404 PART 5 ■ Advanced Design and Deployment Concepts
Address
© Cengage Learning ®
-city: string
-state: string
-postalCode: string
❚❚ Input Models
A slightly enhanced version of Figure 12-16 is included here as Figure 13-4. The
selection of which classes to include is purely an estimate at this point because
we will not determine all the classes until we proceed with the design steps.
However, in this simple example, the preliminary assessment is accurate. Do not
worry if you do happen to omit some required classes. It will become evident
during the design process if something is missing.
The other source of input information comes from the analysis models.
Chapter 5 developed several models for this use case, including a use case
description (Figure 5-2), an activity diagram (Figure 5-4), and a system
sequence diagram (Figure 5-10). Before initiating the design, you will want
to look at all three models to understand as much as possible about the use
case. For this example, focus on the system sequence diagram, which is dupli-
cated here as Figure 13-5. There are three input messages and two return
responses.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 405
:System
Customer
enterCreditCard (cc-info)
© Cengage Learning ®
credit card info details
3. Name each message to reflect the service requested from the destination
object. Identify and include the parameters that the destination object will
require to carry out the requested service. Identify and name any return
messages or return values that need to be returned to origin objects.
Looking at the first input message, createNewCustomer (name, phones,
emails), we decide the following:
1. The required classes for this message are CustomerHandler and Customer.
2. The required message is createNewCustomer and comes from the Clerk to
the :CustomerHandler. The :CustomerHandler then forwards that same
message to the :Customer object. The :Customer object is the appropriate
object to carry out this service. The constructor method in the Customer
class instantiates a new :Customer object. This is shown in the diagram
with a message directly to the :Customer object.
3. The name of the message is appropriate as given in the SSD. The param-
eters on the SSD, however, do not reflect the attributes of the Customer
class. The accountNo and status attributes are both determined by the
constructor. The other attributes—name, mobilePhone, homePhone, and
emailAddress—need to be passed in as arguments. The input parameter list
will be modified to reflect these changes.
The return information is a little more complex. First, the identifier, “aC,”
of the newly created object is returned from :Customer to :CustomerHandler. As
mentioned previously, this provides navigation visibility from :CustomerHandler
to :Customer. Second, all of the data from the :Customer object is returned to
the clerk, including the accountNo and the status. Only the parameter-list is
included because all other items of the message syntax are optional, and not
required for this message.
Figure 13-6 is the result of these steps. Notice that the messages in the fig-
ure are numbered sequentially as they are passed.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
406 PART 5 ■ Advanced Design and Deployment Concepts
«controller»
aC:Customer
:CustomerHandler
Next, you follow the same steps for the second input message, which is
*address details := enterAddress (address).
Notice several things about this input message. First, it begins with an asterisk.
The asterisk means that this message may be sent multiple times. You will carry
that forward to the design. Second, the return data is shown right in the message
syntax. You have the option of showing it that way, or with a separate message
as was done with the first message above. Finally, note that the parameter list
is rather abbreviated. We will need to expand it to reflect the attributes of the
Address class.
The original name of the message is appropriate for the input message and
the second message: enterAddress. However, we change the name to create
Address for the final name to better reflect service requested. The responsible
object for initiating this final request should be the :Customer object. Because
a customer needs navigation visibility to its dependent objects, including its
addresses, it should be the one to invoke the constructor method. The path of
the message thus goes from the controller to :Customer and then to :Address.
Figure 13-7 illustrates the results of extending this message.
The next message, enterCreditCard (cc-info), will follow the same pro-
cess. We also changed the name of this message to be enterAccount because
we are creating a new Account object. We also expanded the parameter list to
reflect the attributes in the Account class. The other decisions with regard to
responsibility and flow of execution are similar to the enterAddress message.
Figure 13-8 shows the results of extending the enterAccount message.
aAdd:Address
«controller»
aC:Customer
:CustomerHandler
Clerk 2.4: (type, no, street, city, state, zip) 2.3: (type, no, street, city, state, zip)
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 407
«controller»
aC:Customer
:CustomerHandler
3.2: aAcc := createAccount
(accNo, type, CCNo, CCDate)
Clerk 3.4: (type, CCNo, CCDate) 3.3: (type, CCNo, CCDate)
aAcc:Account
Figure 13-9 Final communication diagram for Create customer account use case
aAdd:Address
2: *enterAddress (type, no, street, city, state, zip) 2.1: enterAddress (type, no, street, city, state, zip) 2.2: aAdd := createAddress
(accNo, type, no, street, city, state, zip)
«controller»
aC:Customer
:CustomerHandler
Clerk 1.2: (accountNo, name, mobilePh, homePh, email, status) 2.3: (type, no, street, city, state, zip)
3.2: aAcc := createAccount
(accNo, type, CCNo, CCDate)
2.4: (type, no, street, city, state, zip) 3.3: (type, CCNo, CCDate)
aAcc:Account
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
408 PART 5 ■ Advanced Design and Deployment Concepts
Figure 13-10 Design class diagram for methods added from Create customer account
«controller»
CustomerHandler
+createAddress
-accountNo: string {key} (accNo, type, no, street, city, state, zip): Address
-name: string
-mobilePhone: string
-homePhone: string
-status: string
syntax that is used for the design class diagram. Figure 13-10 illustrates the
final design class diagram. You will note that is very similar to Figure 12-22.
In this instance, however, the constructor methods for each class are included.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 409
Figure 13-11 Sample sequence diagram from Create customer account use case
«controller»
aC:Customer
Clerk :CustomerHandler
Activation Lifeline
A Method to return data;
createNewCustomer (name, mobilePh, homePh, email)
note dashed arrow
aAdd:Address
Lifeline
(type, no, street, city, state, zip)
(type, no, street, city, state, zip) Vertical position of Send a constructor message
messages indicates either to the object itself, or
sequence of firing to its lifeline
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
410 PART 5 ■ Advanced Design and Deployment Concepts
Some developers use them; others do not. There are two ways to indicate data
being returned, either by a return assignment with the “:=” operator, or as a return
message using a dashed arrow. Messages that invoke a constructor can be sent
either to a lifeline or to the object itself. Both examples are shown in the figure.
As with a communication diagram, when a message is sent from an originat-
ing object to a destination object, in programming terms, it means that the origi-
nating object is invoking a method on the destination object. Thus, by defining
the messages to various internal objects, we are actually identifying the methods
of that object. The data that is passed by the messages corresponds to the input
parameters of the methods. The return data on a message is the return value from
a method. Hence, once a use case is realized with this detailed design process,
the set of classes and required methods can be extracted so programming can
be completed.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 411
Look at product
reviews
Select accessory
options and
quantity
Add to cart
© Cengage Learning ®
diagram by limiting the solution to the first message. (Note: An additional class,
AccessoryPackage, is required for the use case Search and view accessories, but
because we aren’t designing that use case, it isn’t required for this solution.)
We begin this design by developing the first-cut design class diagam. Refer
back to Figure 4-23, which presented the class diagram for the CSMS sales subsys-
tem. Using that diagram, we can identify the classes that are required for this use
case. The Customer, Cart, and CartItem classes are necessary because the use case
will be adding items for this customer to the customer’s cart. To create a cart item,
the system will need to know what product it is, if there are items in stock, and
the price for the item. Therefore, other classes that are required are InventoryItem,
ProductItem, and PromoOffering. As we develop the solution, we may have to add
classes, but this appears to be sufficient for now. Navigation visibility between
these classes will be from the controller to the Customer class and to the Cart class
once it has been created. The Cart class will be able to access the CartItem class.
The CartItem class should have visibility to the other classes, such as ProductItem
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
412 PART 5 ■ Advanced Design and Deployment Concepts
Customer :System
© Cengage Learning ®
(description, price, extendedPrice)
and InventoryItem that contain the necessary information. Figure 13-14 shows
the first-cut design class diagram, which includes several additions to the domain
model. In Figure 13-14, several key identifier fields have been added to some classes.
One correction to the domain model was also made. In Chapter 9 during the nor-
malization process the regularPrice attribute was moved out of the PromoOffering
class and into the ProductItem class, which is where it correctly belongs.
To design this use case, we will follow the same steps that were outlined in
the “Extend Input Messages” section for use case realization using communi-
cation diagrams. Even though this use case has fewer input messages than the
previous example (Create customer account), the processing required to execute
a message is more complex.
Let’s take the first input message, addItemToCart. This message first comes
to the CartHandler. Obviously, it is not possible to add an item to a cart if there
is no cart. So how do you create a cart? One solution is to require the user/actor
to create a new cart. This is a poor idea. It is never a good idea to require the
user to perform an act if the system can do it automatically. The system can be
made smart enough to know if it needs to create an online cart first. How can
the system know? There are several ways to design this process. Let’s use the
perfect technology assumption that the user has logged on. So :CartHandler
should have a reference to the :Customer object. However, if there is no refer-
ence to an online cart object, then it needs to be created. The next question is,
what object should create the new online cart object? From the domain model,
you can see that an online cart object has a cardinality of exactly one to a cus-
tomer object. So a cart cannot exist without a customer, and from the design
class diagram, you can see that the customer must have visibility to the online
cart. Hence :Customer is the obvious object to create the :OnLineCart object.
Figure 13-15 shows this first step. The :CartHandler checks to see if it is the
first item, and if so, sends a createCart message to :Customer. Notice the true/
false condition on that message. The :Customer object sends a create message
directly to :OnlineCart to instantiate a new cart. A reference to the new cart is
returned first to :Customer, which then forwards it on to :CartHandler. Now
both have navigation visibility to the newly created online cart. Figure 13-15
shows both methods of returning data.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 413
© Cengage Learning ®
-averageCost: currency -pictureID: string
-reorderQuantity: int
-dateLastOrder: date
-dateLastShipment: date
:CartHandler :Customer
Customer
(aCrt)
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
414 PART 5 ■ Advanced Design and Deployment Concepts
Now that the cart is created, the system can add the item to the cart. Also,
notice that if it is not the first item, then this sequence of messages is skipped and
the system goes directly to adding the item to the cart. Because :CartH andler
now has visibility to :OnlineCart, it sends a message directly to the cart to add
the appropriate item. :OnlineCart creates a new cart item and passes the data to
:CartItem to instantiate a new cart item. :CartItem retrieves the necessary data
to complete its attributes. We are assuming in this case that the price is the pro-
motional price. Once the cart item has created itself, it returns information back
to :OnlineCart, which returns it to :CartHandler and eventually to the user/
customer. Figure 13-16 illustrates this next set of messages.
As you can see, this simple input message extends to quite a bit of internal
activity. How did we know what to do? We observed the attributes of :CartItem
and noted what classes contained the information that was needed. :CartItem is
responsible for obtaining the data to instantiate itself. It simply went to the nec-
essary objects to obtain that data.
Referring back to Figure 13-13, note that there is another input message,
addAccessoryToCart (…), with the same input parameters. As you think about
this, note that adding an accessory is the same activity as adding an item. Acces-
sories are just items that are associated with products for promotions to the cus-
tomer. Once an accessory item is selected, it simply becomes an item. Hence, the
same set of internal messages are required. The only difference is that adding
accessories is an optional activity. In Chapter 5, Figures 5-8 and 5-9 showed you
how to indicate a loop of messages or an optional set of messages. In this case, the
[firstItem]createCart ( )
aCrt := createCart ( )
aCrt:OnlineCart
(aCrt)
:CartItem
price:=getPrice ( )
description:=getDesc ( )
status:=updateQty (qty)
(description, price)
(description, price)
(description, price, extended price)
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 415
SSD indicates a repeating message for the accessories. Figure 13-17 is the full use
case with both sets of messages shown, one set for an item and a repeating set for
the accessories. The repeating messages inside the Opt, Loop frame are the same
as those developed for the first input message, but without the createCart message.
As you identify the specific messages, along with source and destination and
the passed parameters, you need to consider some critical issues. As before, an
important question is: Which object is the source or initiator of a message? If
the message is a query message, the source is the object that needs information.
Figure 13-17 Sequence diagram for Fill shopping cart use case
[firstItem]createCart ( )
aCrt := createCart ( )
aCrt:OnlineCart
(aCrt)
createCartItem
addItem (promoNo, prodID, size, color, qty)
(promoNo, prodID, size, color, qty)
:CartItem
price:=getPrice ( )
description:=getDesc ( )
status:=updateQty (qty)
(description, price)
(description, price)
(description, price,
extended price)
Loop
[Accessory]
addAccessory
(promoNo, prodID, size, color, qty)
addItem createCartItem
(promoNo, prodID, size, color, qty) (promoNo, prodID, size, color, qty)
price:=getPrice ( )
description:=getDesc ( )
status:=updateQty (qty)
© Cengage Learning ®
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
416 PART 5 ■ Advanced Design and Deployment Concepts
If the message is an update or create message, the source is the object that con-
trols the other object or that has the information necessary for its creation.
Another important consideration is navigation visibility. To send a message
to the correct destination object, the source object must have visibility to the
destination object. Remember that the purpose of doing design is to prepare
for programming. As a designer, you must think about how the program will
work and consider programming issues. Given these two considerations and the
source considerations discussed in the previous paragraph, we have determined
that the following internal messages will be required. For each message, a source
object and a destination object have been identified.
■■ createCart(). The :CartHandler object will know whether it has received
earlier messages to add items. If it hasn’t, it knows it must tell the :Customer
object to create a cart.
■■ aCrt:=createCart(). The :Customer object owns the :OnlineCart object.
■■ addItem(). A forwarded version of the input message from :CartHandler to
:OnlineCart. Because :CartItem objects are dependent on a cart, :OnlineCart
is the logical object to create :CartItem objects. The controller has visibility
to :OnlineCart from the previous return message, when aCrt was returned.
■■ createCartItem(). The internal message from :Cart to :CartItem. Because
:CartItem will be responsible for obtaining the data for its attributes, it
needs visibility to :PromoOffering, :ProductItem, and :InventoryItem. As a
result, information to find those objects is sent as parameters.
■■ getPrice(). The message to get the price from the :PromoOffering object.
The :CartItem initiates the message.
■■ getDescription(). The message initiated by :CartItem to get the description
from :ProductItem.
■■ updateQty(qty). The message that checks for sufficient quantity on hand.
This message also initiates updates of the quantity on hand. :CartItem
initiates the message.
❚❚ Guidelines
Designing a use case or scenario by using sequence diagrams involves perform-
ing these tasks:
■■ Take each input message and determine all the internal messages that result
from that input. For each message, determine its objective. Determine what
information is needed, what class needs it (the destination), and what class
provides it (the source).
■■ As you work with each input message, identify the complete set of classes
that will be affected by the message. In other words, select all the objects
from the domain class diagram that need to be involved. In Chapter 5, you
learned about use case preconditions and postconditions. Any classes that are
listed in either the preconditions or postconditions should be included in the
design. Other classes to include are those that are created, classes updated
during the use case, and those that provide information used in the use case.
■■ Flesh out the components for each message; that is, add iteration, true/false con-
ditions, return values, and passed parameters. The passed parameters should be
based on the attributes found in the domain class diagram. Return values and
passed parameters can be attributes, but they may also be objects from classes.
These three steps will produce the preliminary design. Refinements and
modifications may be necessary; again, we are focusing only on the problem
domain classes involved in the use case.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 417
❚❚ Assumptions
The development of the first-cut sequence diagram is based on several assump-
tions, including:
■■ Perfect technology assumption. You first encountered this assumption in
Chapter 5, when identifying business events. The assumption continues
here. You don’t include messages such as the user having to log on.
■■ Perfect memory assumption. You might have noticed our assumption that
the necessary objects were in memory and available for the use case. We
didn’t ask whether those objects were created in memory. We will change
this assumption when we get to multilayer design. In multiple-layer design,
we do include the steps necessary to create objects in memory.
■■ Perfect solution assumption. The first-cut sequence diagram assumes that
there are no exception conditions. No logic is included to handle a situation
in which the requested catalog or product isn’t found. More serious excep-
tion conditions, such as the failure of a credit check, might also be encoun-
tered. Many developers design the basic processing steps first and then add
the other messages and processes to handle the exception conditions later.
We do the same here.
One advantage of adding it to the sequence diagram is that the programmer can
see how the view layer classes integrate with the rest of the design. It becomes
a check to make sure the design is correct and complete. It is a good practice to
verify several use cases to ensure that the developers understand how the view
layer represents the user-interface design and how all the elements integrate
together for a smooth program execution. Thus, input for view layer design
includes the use case description, the SSD, the activity diagrams, the first-cut
design class diagram, and, finally, the user-interface layouts or mock-ups.
User-interface design and the integration of the view layer into a sequence
diagram are made even more complex by the fact that many systems require
both a Web-based interface and an internal, network-based interface. Fortu-
nately, browsers are becoming more sophisticated, so many new systems can
now be designed for only one type of interface. Designing a system with multiple
user interfaces is a complex endeavor.
Let’s return to the Add customer account use case and add the view layer.
Remember from the discussion of communication diagrams that there are three
input messages: createNewCustomer, enterAddress, and enterAccount. Let’s
assume that, from the results of our user-interface design, a separate input form
for each message is required. Let’s add those classes to the sequence diagram.
The starting point is Figure 13-11, which is the sequence diagram with the prob-
lem domain classes. The process to add the view layer is simply to add an object
for each input form or screen. First add the appropriate messages from the Clerk
to the input «view» objects. In this instance, the messages are the ones identified
from the SSD, and which were used in Figure 13-11. Additional messages are
added for the :CustWindow to open the :AddrWindow, and the :AddrWindow
to open the :AcctWindow. Figure 13-18 illustrates the resulting diagram with
both the domain and view layers.
In Figure 13-18, we just added a single view object for each message. This
approach was rather straightforward. If we look at the other use case we have
been using, Fill shopping cart, we have a more complex example. Remember
that the Fill shopping cart use case included other use cases for Search for item
and View accessory combinations. Obviously, all those use cases go together
for a rich and efficient user experience. In Figure 13-19, we have added the
two view layer objects for searching items and viewing accessories. The first
input message, addItem ( ), will go through the :SearchItemWindow object.
In other words, when the customer finds something he or she likes, he or she
will initiate adding it to his or her cart from that window. The message then
causes a detailed :AddItemWindow object to display and show the details to
verify the addition to the cart. This later window will forward the message on
to :CartHandler.
Once the item has been added to the cart, another window displays that
shows the results of adding this new item. Depending on the design of the user
interface, this window might show the single newly added item or it might also
show the total shopping cart.
The next three view layer objects, :ViewAccessWindow, :AddAccess
Window, and :DisplayItem+AccessWindow, function in a manner similar to the
other view layer objects. The only difference is that the data includes the item
and the accessories that have been added to the online cart.
Adding the view layer to your design is a good way to verify that the user
interface that was developed with the users is consistent with the application
design. All the input messages that were identified and documented on SSDs
must be handled by the user interface. If there are messages without input win-
dows or windows without messages, you will know that part of the design is
incomplete and that more definition is required.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 419
Figure 13-18 Add customer account use case with view layer added
«view» «controller»
aC:Customer
:CustWindow :CustomerHandler
Clerk
createNewCustomer
(name, mobilePh, homePh, email)
createNewCustomer
aC:=createNewCustomer
(name, mobilePh, homePh, email)
(name, mobilePh, homePh, email)
showAddrWindow ( )
Loop
[Address]
«view»
:AddrWindow
enterAddress
(type,no,street,city,state,zip) enterAddress
aAdd:=createAddress
(type,no,street,city,state,zip) enterAddress (accNo, type, no, street, city, state, zip)
(type,no,street,city,state,zip)
aAdd:Address
«view»
:AcctWindow
enterAccount
(type, CCNo, CCDate) enterAccount aAcc:=createAccount
(type, CCNo, CCDate enterAccount (accNo, type, CCNo, CCDate)
(type, CCNo, CCDate)
aAcc:Account
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
420 PART 5 ■ Advanced Design and Deployment Concepts
Figure 13-19 Partial sequence diagram for the Fill shopping cart use case with view layer
«view» «controller»
:SearchItemWindow :CartHandler
Customer
addItem
(promoNo, prodID, size, color, qty)
«view»
:AddItemWindow
addItem
(promoNo, prodID, size, color, qty)
addItem
(promoNo, prodID, size, color, qty)
«view»
:DisplayItemWindow
(description, price, extendedPrice)
«view»
:ViewAccessWindow
addAccessory
(promoNo, prodID, size, color, qty)
«view»
:AddAccessWindow
addAccessory
(promoNo, prodID, size, color, qty)
addAccessory
(promoNo, prodID, size, color, qty)
from the database. One of the problems with object-oriented programs that use
relational databases is that there is a slight mismatch between programming lan-
guages and database SQL statements. For example, in a database, tables are
linked through the use of foreign keys (see Figure 9-9), such as a cart having a
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 421
CustomerID as a column so the order can be joined with the customer in a rela-
tional join. However, in object-oriented programming languages, the navigation
is often in the opposite direction (i.e., the Customer class may have an array of
references that point to the OnlineCart objects, which are in computer memory
and are being processed by the system). In other words, design classes don’t have
foreign keys.
This chapter takes a somewhat simplified design approach in order to teach
the basic ideas without getting embroiled in the complexities of database access.
Let us assume that every domain object has a table in a relational database.
(More complex situations exist in which tables must be combined to provide the
correct set of objects in memory.)
When a new persistent object is created in memory, the constructor method
often initiates the process to write it to the database. When an object is updated,
it also needs to be written to the database. The common method to do that
is simply to send a message to the data access object. Either the set of object
attributes can be sent as parameters or simply as a reference to the object itself.
The data access method can pull out the attributes, format an SQL insert or
update statement, and write it to the database. Figure 13-20 is an enhancement
of Figure 13-18 with the data access layer added. It is a straightforward addition
to add three data access objects and have the newly created objects send mes-
sages to write themselves out to the database. Although this diagram is fairly
busy, it is organized with the view layer on the left, the problem domain layer in
the middle, and the data access layer on the right.
Figure 13-20 Create customer account use case with view layer and data layer
«view» «controller»
aC:Customer
:CustWindow :CustomerHandler
Clerk
createNewCustomer «dataAccess»
(name, mobilePh, homePh, email) :CustomerDA
createNewCustomer aC:=createNewCustomer
(name, mobilePh, homePh, email) (name, mobilePh, homePh, email)
«dataAccess»
showAddrWindow ( ) :AddressDA
writeDB (ac)
(name, mobilePh, homePh, email)
«dataAccess»
:AddressDA
Loop
[Address] «view»
:AddrWindow
enterAddress
(type,no,street,city,state,zip) enterAddress aAdd:=createAddress
(type,no,street,city,state,zip) enterAddress (accNo,type,no,street,city,state,zip)
(type,no,street,city,state,zip)
aAdd:Address
showAcctWindow ( ) (type,no,street,city,state,zip)
(type,no,street,city,state,zip)
writeDB (aAdd)
«view»
:AcctWindow
enterAccount
(type, CCNo, CCDate) enterAccount
(type, CCNo, CCDate enterAccount aACC:=createAccount
(type, CCNo, CCDate) (accNo, type, CCNo, CCDate)
aAcc:Account
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
422 PART 5 ■ Advanced Design and Deployment Concepts
Figure 13-21 Partial sequence diagram with data access as part of constructor
:PromoOffering
aPO:PromoOffering :PromoOfferingDA
:CartItem
Becomes :CartItem
price:=getPrice ( )
aPO:=findPromo (promoID, ProdID
readPO ( )
price:=getPrice ( )
❚❚ The Data Access Layer for the Fill Shopping Cart Use Case
Figure 13-23 is a portion of the Fill shopping cart use case from Figure 13-16. In
this diagram, we have only included the AddItem message to limit the complexity
of the drawing. The data access classes have all been added along the top. The first
two, :OnlineCartDA and :CartItemDA, are needed so that the system can write
out the data from the newly created online cart and cart item. At the bottom of the
lifeline of each of those two objects is the save statement, which causes the data to
be written to the database. The next three data access objects, :PromoOfferDA,
:ProductDA, and :InventoryDA, are needed to retrieve data as part of the construc-
tor for :PromoOffering, :ProductItem, and :InventoryItem. Each of those sets of
messages function as explained in Figure 13-21. As you can see, adding the data
access layer can increase the level of complexity of the drawing quite dramatically.
It is important during this process to ensure that source objects have navi-
gation visibility to destination objects so messages can be sent. We assume but
don’t show that the data access objects have global visibility. (In your program-
ming class, you will learn that factory or singleton classes are often designed
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 423
Figure 13-22 Partial sequence diagram with data access prior to constructor
PromoOffering
aPO:PromoOffering :PromoOfferingDA
:CartItem
Becomes :CartItem
price:=getPrice ( )
createPO (...)
price:=getPrice ( )
Figure 13-23 Partial sequence diagram for the Fill shopping cart use case with data access layer
:CartHandler
aCrt:OnlineCart aP:PromoOffering aPl:ProductItem all:InventoryItem
Customer
aCl:CartItem
addItem
(promoNo, ProdID, size, color, qty)
aP:=findPromo (promoID, prodID)
price:=getPrice ( ) readPO ( )
aPl:=findProdItem (prodID)
description:=getDesc ( )
readProd ( )
(description, price)
all:=findInvItem (prodID, size, color)
(description, price)
status:=updateQty (qty)
readInv ( )
(description, price, extended price)
saveCartItem (aCI)
saveCart (aCrt)
with global methods.) After the appropriate problem domain object is created, a
reference to it is returned to the object that needs visibility. As you look closely
at Figure 13-23, note that every object that sends a message to another object
must have navigation visibility to that object. Remember this important design
point as you develop your design solutions.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
424 PART 5 ■ Advanced Design and Deployment Concepts
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 13 ■ Object-Oriented Design: Use Case Realization 425
Figure 13-24 Updated design class diagram for the domain layer
«controller» «controller»
CustomerHandler CartHandler
+createCustomer (name, mobilephone, homePhone, email) +addItem (promoNo, prodID, size, color, qty)
+enterAddress (type, street, city, state, zip) +addAccessory (promoNo, prodID, size, color, qty)
+enterAccount (type, ccNo, ccDate)
Customer OnlineCart
-accountNo: string {key} -saleID: int {key}
-name: string -saleDateTime: date
-mobilePhone: string -priorityCode: string
-homePhone: string -S&H: currency
-status: string -tax: currency
-totalAmt: currency
+createNewCustomer (name, mobilePh, homePh, +createCart ( )
email): Customer +addItem (promoID, prodID, size, color, qty)
+enterAddress(type, street, city, state, zip)
+enterAccount(type, ccNo, ccDate)
+createCart ( )
CartItem
Address
-accountNo: string {key} InventoryItem PromoOffering
-typeOfAddress: string
-number: string -inventoryID: int {key} -promoNo: string
-street: string -productID: string -promoPrice: currency
-city: string -size: string
-state: string -color: string +getPrice ( ): currency
-postalCode: string -options: string
-quantityOnHand: int
+createAddress (accNo, type, no, street, city, state, zip) -averageCost: currency ProductItem
-reorderQuantity: int
-dateLastOrder: date -productID: string {key}
-dateLastShipment: date -gender: string
-description: string
-supplier: string
+updateQty (qty): string
© Cengage Learning ®
-manufacturer: string
-regularPrice: currency
-pictureID: string
+getDesc ( ): string
from design class diagrams and interaction diagrams for each use case. Figure 13-25
is only a partial package diagram because the packages contain only the classes from
the use case interaction diagrams that were developed in this chapter.
The other symbol used on a package diagram is a dashed arrow, which
dependency relationship a relationship
between packages, classes, or use cases represents a dependency relationship. The arrow’s tail is connected to the
in which a change in the independent item package that is dependent, and the arrowhead is connected to the independent
requires a change in the dependent item package. To read a dependency relationship, read it in the direction of the arrow.
Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.