CH 07
CH 07
Top Compartment
In the UML, each class is modeled in a class diagram as a rectangle with three compartments.
The top one contains the class’s name centered horizontally in boldface.
Middle Compartment
The middle compartment contains the class’s attributes, which correspond to instance
variables in Java.
Bottom Compartment
The bottom compartment contains the class’s operations, which correspond to methods and
constructors in Java.
The UML represents instance variables as an attribute name, followed by a colon and the type.
Private attributes are preceded by a minus sign (–) in the UML.
The UML models operations by listing the operation name followed by a set of parentheses.
A plus sign (+) in front of the operation name indicates that the operation is a public one in the
UML (i.e., a public method in Java).
Return Types
The UML indicates an operation’s return type by placing a colon and the return type after the
parentheses following the operation name.
UML class diagrams do not specify return types for operations that do not return values.
Declaring instance variables private is known as data hiding or information hiding.
Parameters
The UML models a parameter of an operation by listing the parameter name, followed by a
colon and the parameter type between the parentheses after the operation name
package.
An import declaration is not required when one class in a package uses another in the same package.
An import- declaration is not required if you always refer to a class with its fully qualified class name,
Default Constructor
If a class does not define constructors, the compiler provides a default constructor with no
parameters, and the class’s instance variables are initialized to their default values.
We now declare an Account class that maintains the balance of a bank account in addition
to the name.
Most account balances are not integers.
So, class Account represents the account balance as a double.