Chapter 6
Object-Oriented Designs

   6.1 Background
   6.2 Objects
   6.3 Cooperating Objects
   6.4 Designing Objects
   6.5 Designing with Objects
   6.6 Classes and Instances
   6.7 Example: Apples
   6.8 Example: Clocks
   6.9 Assignment #7: Object-Oriented Designs

6.1 Background

6.2 Objects

6.3 Cooperating Objects

6.4 Designing Objects

Issues to be considered

6.5 Designing with Objects

Issues to be considered

6.6 Classes and Instances

6.7 Example: Apples

Apple
|--------------------------|
|    |          --         |
|   |||-|||    |--|-----|  |
| |||------    ---|---- |- |
| ||      |     ||-------- |
|  |------|     apple 2    |
|  apple 1                  |
----------------------------
Class name: Apple
 
Instance properties (instance fields): color, weight
Class properties (class fields): count, weight
Constructor: adds an apple of specified color and weight, and adjusts the class fields
Methods:  
 
Instance locators (instance handlers): apple 1, apple 2
Instance states: state(apple 1)=(green, 0.25 pound), state(apple 2)=(red, 0.3 pound)
Class state: (2, 0.55 pound)

Q&A

6.8 Example: Clocks

|-Clock-------------------|
|   -|||||               |
|  --  ---|      late     |
|  -|    --     --||||-  |
|   |||||-      ---|  |  |
|  early         -||||--  |
-------------------------
Class name: Clock
 
Instance properties (instance fields): hours, minutes, seconds
Class properties (class fields):
  • max time
  • min time
  • total cost
Constructor: adds a clock set to the requested time
Instance functions (methods):
  • advance the time by one second
  • set the clock to a requested time
  • display the clock time
Class functions (methods): show average (of min and max) time
 
Instance locators (instance handlers): early, late
Instance states: state(early) = 3:00:00, state(late) = 5:45:22
Class state: state = (3:00:00, 5:45:22)
Notes

6.9 Assignment #7: Object-Oriented Designs

Due: Mo, Apr 21, midnight

Write a report which offers a class of objects of your liking and shows the following features.

  1. The properties available for the objects
  2. The properties available for the class
  3. The functions the objects can perform
  4. Three examples of the possible states of the objects
Note: none of the above items should be empty.

Assume ‘lab7’ for the submit program.

Q&A