Skip to content

Week 12 - Objects

Object Oriented Programming

  • It’s Just the Beginning, but WHY???

We Can Make Models, and Patterns, that Help Us Solve Problems

UML Model of a Room

Favor Composition over Inheritence

  • Wait, what’s Inheritance? Inheritance in a Nutshell
  • OK, that makes sense, but what is Composition? Composition in a Nutshell
    • But how can I favor composition?
      • One way is Interfaces

Walk Through Lab Code

Lab 10

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