mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-28 18:23:08 +00:00
Use enums instead os switch blocks
Its better to use enums instead of switch blocks which makes the code longer and difficult to maintain as and when new state appears.
This commit is contained in:
@@ -33,7 +33,9 @@ package com.iluwatar.observer {
|
||||
+ RAINY {static}
|
||||
+ SUNNY {static}
|
||||
+ WINDY {static}
|
||||
+ description String
|
||||
+ toString() : String
|
||||
+ getDescription() : String
|
||||
+ valueOf(name : String) : WeatherType {static}
|
||||
+ values() : WeatherType[] {static}
|
||||
}
|
||||
@@ -71,10 +73,10 @@ package com.iluwatar.observer.generic {
|
||||
Weather --> "-currentWeather" WeatherType
|
||||
GWeather --> "-currentWeather" WeatherType
|
||||
Weather --> "-observers" WeatherObserver
|
||||
Hobbits ..|> WeatherObserver
|
||||
Orcs ..|> WeatherObserver
|
||||
GHobbits ..|> Race
|
||||
GOrcs ..|> Race
|
||||
GWeather --|> Observable
|
||||
Race --|> Observer
|
||||
@enduml
|
||||
Hobbits ..|> WeatherObserver
|
||||
Orcs ..|> WeatherObserver
|
||||
GHobbits ..|> Race
|
||||
GOrcs ..|> Race
|
||||
GWeather --|> Observable
|
||||
Race --|> Observer
|
||||
@enduml
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
Reference in New Issue
Block a user