Page 303 -
P. 303
270 Part 3 • the analysis Process
requirements as well as processing requirements. Later in the chapter we will discuss the mean-
ing of the diamond symbols shown in this figure.
The attributes (or properties) are usually designated as private, or only available in the
object. This is represented on a class diagram by a minus sign in front of the attribute name.
Attributes may also be protected, indicated with a pound symbol (#). These attributes are hidden
from all classes except immediate subclasses. Under rare circumstances, an attribute is public,
meaning that it is visible to other objects outside its class. Making attributes private means that
the attributes are only available to outside objects through the class methods, a technique called
encapsulation, or information hiding.
A class diagram may show just the class name; or the class name and attributes; or the class
name, attributes, and methods. Showing only the class name is useful when the diagram is very
complex and includes many classes. If the diagram is simpler, attributes and methods may be
included. When attributes are included, there are three ways to show the attribute information.
The simplest is to include only the attribute name, which takes the least amount of space.
The type of data (such as string, double, integer, or date) may be included on a class dia-
gram. The most complete descriptions would include an equal sign (=) after the type of data,
followed by the initial value for the attribute. Figure 10.14 illustrates class attributes.
If the attribute must take on one of a finite number of values, such as a student type with
values of F for full-time, P for part-time, and N for nonmatriculating, these may be included in
curly brackets separated by commas as shown here — studentType:char{F,P,N}.
Information hiding means that objects’ methods must be available to other classes, so meth-
ods are often public, meaning that they may be invoked from other classes. On a class diagram,
public messages (and any public attributes) are shown with a plus sign (+) in front of them.
Methods also have parentheses after them, indicating that data may be passed as parameters
along with the message. The message parameters, as well as the type of data, may be included
on the class diagram.
There are two types of methods: standard and custom. Standard methods are basic things
that all classes of objects know how to do, such as create a new object instance. Custom methods
are designed for a specific class.
Method Overloading
Method overloading refers to including the same method (or operation) several times in a class.
The method signature includes the method name and the parameters included with the method.
The same method may be defined more than once in a given class, as long as the parameters sent
as part of the message are different; that is, there must be a different message signature. There
may be a different number of parameters, or the parameters might be a different type, such as a
number in one method and a string in another method. An example of method overloading may
be found in the use of a plus sign in many programming languages. If the attributes on either side
of the plus sign are numbers, the two numbers are added. If the attributes are strings of charac-
ters, the strings are concatenated to form one long string.
In a bank deposit example, a deposit slip could contain just the amount of the deposit, in
which case the bank would deposit the entire amount, or it could contain the deposit amount
and the amount of cash to be returned. Both situations would use a deposit check method, but
the parameters (one situation would also request the amount of cash to be returned) would be
different.
Figure 10.14 Student
An extended Student class that studentNumber: Integer
shows the type of data and, in lastName: String
some cases, its initial value or firstName: String
default value. creditsCompleted: Decimal=0.0
gradePointAverage: Decimal=0.0
currentStudent: Boolean=Y
dateEnrolled: Date=
new( )
changeStudent( )
viewStudent( )