Week 12 - Objects
Object Oriented Programming¶
- It’s Just the Beginning, but WHY???
We Can Make Models, and Patterns, that Help Us Solve Problems¶
Favor Composition over Inheritence¶
- Wait, what’s Inheritance?
- OK, that makes sense, but what is Composition?
- But how can I favor composition?
- One way is Interfaces
- But how can I favor composition?
Walk Through Lab Code¶
classDiagram
class WeatherStation
WeatherStation : -URL url
WeatherStation : -List~Display~ displays
WeatherStation : -Gson gson
WeatherStation : -float temperature
WeatherStation : -float humidity
WeatherStation : -float pressure
WeatherStation : +WeatherStation()
WeatherStation : +registerDisplay(display)
WeatherStation : +removeDisplay(display)
WeatherStation : +notifyDisplays()
WeatherStation : +getTemperature() float
WeatherStation : +getHumidity() float
WeatherStation : +getPressure() float
WeatherStation : +measure()
class I_Display
I_Display : update()
I_Display : display()
class CurrentConditions
CurrentConditions: -WeatherStation ws
CurrentConditions : -float temperature
CurrentConditions : -float humidity
CurrentConditions : +CurrentConditions(weatherstation)
CurrentConditions : update()
CurrentConditions : display()
class StatisticsDisplay
StatisticsDisplay: -WeatherStation ws
StatisticsDisplay : -float temperatureMin
StatisticsDisplay : -float temperatureMax
StatisticsDisplay : -float temperatureTotal
StatisticsDisplay : -int numReadings
StatisticsDisplay : +StatisticsDisplay(weatherstation)
StatisticsDisplay : update()
StatisticsDisplay : display()
class ForecastDisplay
ForecastDisplay: -WeatherStation ws
ForecastDisplay : -float currentPressure
ForecastDisplay : -float lastPressure
ForecastDisplay : +ForecastDisplay(weatherstation)
ForecastDisplay : update()
ForecastDisplay : display()
I_Display <|.. CurrentConditions
I_Display <|.. StatisticsDisplay
I_Display <|.. ForecastDisplay
WeatherStation --* CurrentConditions
WeatherStation --* StatisticsDisplay
WeatherStation --* ForecastDisplay
I_Display --* WeatherStation