Skip to content
thesarfo

Note

OO Design Basics (Head First Java)

The state-vs-behavior framing for designing a class — what an object knows vs. what it does.

views 0

When designing a class, think about the objects that will be created from it:

  1. Things the object knows
  2. Things the object does

For instance:

  • Class ShoppingCart — knows cartContents; does addToCart(), removeFromCart(), checkOut().
  • Class Alarm — knows alarmTime, alarmMode; does setAlarmTime(), getAlarmTime(), isAlarmSet(), snooze().

Things an object knows about itself are its instance variables (state). Things it can do are its methods (behavior).