-
Notifications
You must be signed in to change notification settings - Fork 14
Create EX12.rst #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Create EX12.rst #96
Conversation
Solutions/EX12.rst
Outdated
| .. code:: java | ||
|
|
||
| public Cargo(CargoType cargoType) { | ||
| this.name = cargoType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name pole mõistlik muutuja. hiljem tekitab segadust
Solutions/EX12.rst
Outdated
| .. code:: java | ||
|
|
||
| private boolean cargosAreOk() { | ||
| return cargos.size() == 0 || cargos.size() == 1 || cargos.contains("FUEL") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
siin pole mõistlik kasutada Stringe võrdlemiseks. Pigem võiks olla list CargoType elementidest ja kontrollida neid.
aga veel õigem oleks üldse teha nii, et CargoType juures on see võrdlus. võid mõelda nii, et kui lisatakse uus CargoType, siis ei pea koodis mitmes kohas käima muutmas. kui loogika konfliktsetest tüüpides on kõik näiteks enumi juures, siis on vähem vaja muudatusi teha hiljem koodis.
Solutions/EX12.rst
Outdated
| if (engineList.size() > 0) { | ||
| if (cargoTypes.length == 1 && cargoTypes[0].getDangerLevel() > this.getBestEngine().get() | ||
| .getRiskLevel()) { | ||
| try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sedasi pole mõtet erindit (exception) kasutada. siinne kood teeb seda, et viskab erindi TooRiskyCargo, seejärel kohe püüab selle erindi ning prindib teksti ja tagastab Optional.empty(). Sama hästi võiks kogu try-catch ära jääda ja oleks lihtsalt print ja return. erindi mõte on see, et see visatakse väljapoole meetodit või siis seda püütakse kinni mingi meetodi puhul, mis selle võib tõstatada. aga selliselt, et tõstatad ja kohe püüad kinni - selliselt ei ole sellest kasu.
No description provided.