Page 816 - Introduction to Programming with Java: A Problem Solving Approach
P. 816
782 Appendix 7 UML Diagrams
Commission
+COMMISSION_RATE: double = 0.10
+addSales(sales : double) : void
Commissioned
-salary : double
+Salaried(name : String, salary : double)
+getPay() : double
Salaried2
-salary : double
+Salaried(name : String,
salary : double) +getPay() : double
Hourly2
-hourlyRate : double -hours : double = 0.0
+Hourly(name:String, rate : double)
+getPay() : double +addHours
(hours : double) : void
*
+Salaried(name : String,salary : double)
*
*
+getPay() : double
+main() : void
*1
11
1
-name : String
+Employee(name:String) +getPay() : double +printPay(date : int) : void
SalariedAndCommissioned
-salary : double
Payroll3
Apago PDF Enhancer
Employee2
Figure A7.4 UML Class diagram for the Payroll3 program
This shows inheritance from classes and implementation of an interface. It also shows composition. Since every association line in this figure has some kind of arrowhead, all its associations are unidirectional. The dashed association between Payroll3 and Employee2 is a simple dependence. That means the Employee2 type appears in the declaration of a parameter or local variable somewhere in Payroll3’s code.
end of this dashed association line indicates that the association is unidirectional. Payroll3 knows about Employees2, but Employees2 does not know about Payroll3. Thus, changes to Employees2 might require changes to Payroll3, but changes to Payroll3 would never require changes to Employees2. UML uses dashed association lines for parameter and local variable dependencies, and it uses solid associa- tion lines for instance and class variable dependencies.
As described in the optional section at the end of Chapter 12, UML also uses dashed association lines to connect an association class to an association between or among other classes. Figure 12.22 shows an as- sociation line connecting the three classes, SalesPerson2, Customer, and Car. Although we did not discuss this detail in Chapter 12, the fact that this association line is solid and has no barbed arrowheads at its ends suggests that each of these three classes has instance variables that refer to particular instances of the other two classes.
The association class called Sales makes these additional references unnecessary, because the Sales class can hold all these references itself—in one place. Thus, this extra association class reduces the number of reference variables. More importantly, it eliminates the need to alter the definition of the SalesPerson2 and Car classes when we add a Customer class and a Sale association to the program. To reflect the fact that the SalesPerson2, Car, and Customer classes do not need any references to instances of other