I have a task which requires me to draw a UML diagram based on the description. I have received the solution (see the photo). However, I can't figure out the solution and have a few questions why the solution is the way it is. I have described these below.
Description:
The contract of a prepaid cell phone should be modelled and implemented. A basic contract has a contract number (of type int) and a balance (of type double), but no monthly charges. The contract number is not automatically generated, but is to be set as a parameter by the constructor as well as the initial balance. The balance has a getter and a setter. The following options can be added to a contract (if needed also several times):
- 100 MB of data (monthly charge 1.00 €)
- 50 SMS (monthly charge 0.50 €)
- 50 minutes (monthly charge 1.50 €)
- Double Transfer Rate (monthly charge 2.00 €) Implement this this requirement with the help of the decorator pattern. All contract elements should be able to understand the methods
getCharges():double
,getBalance():double
andsetBalance (double)
.
The method getCharges()
should provide the monthly charge of a contract with all its options selected. The methods getBalance()
and setBalance(…)
should be passed through and access the basic contract.
Exercise:
- Draw an UML-Diagram with all the classes / interfaces and their relationships, fields and methods (no constructors needed).
- Also provide a client class which holds a contract.
Solution:
Question:
- Why does
Option
once have a dashed line and a normal line toContract
? - Why are the
Minutes
not listed as a class likeData
andSMS
? - Why does
Phone
andDoubleTransfer
have no connection to the other classes?
Aucun commentaire:
Enregistrer un commentaire