Skip to main content

CSC 322.01, Class 23: Work time (and OOD)


  • Preliminaries
    • Notes and news
    • Upcoming work
    • Extra credit
    • Questions
  • Review of inheritance
  • Work time

News / Etc.

  • Remember the project reports are due EVERY FRIDAY at 5 p.m.
    • Make sure to include all the alumni, me, KY, GB, and MG in the recipient list
  • Please finish registering if you have not done so already.

Upcoming Work

Please put your assignments in your planners or equivalent.

  • For Tuesday: Read Chapter 7 of POODR.
  • Regular work on projects.
  • Weekly Project Report, TOMORROW at 5pm
    • What did you accomplish this past week?
    • What do you hope to accomplish in the coming week?
    • What obstacles stand in your way?
    • What resources do you need to help you accomplish your work?
  • Presentations Tuesday
    • What you accomplished (and did not accomplish)
    • Velocity
    • Demo
    • Plans
    • Q&A

Good things to do

Note: I do not do extra credit in two-credit classes.

  • Convocation TODAY!
  • Students of voice recitals Friday at 4:15 and 7:30 p.m.
  • CS Extras Tuesday


Review of inheritance

What new about inheritance did you take from chapter 6.

  • Different perspective on inheritance. Sam thinks of inheritance as “code and fields get copied to subclass”. Metz thinks of inheritance as “messages are automatically delegated to superclass”.
  • Reinforcement of “hash as parameter”. If the hash is a parameter to the constuctor, it’s much easier for the subclass to grab only what it needs and then to pass everything else to the superclass.
    • Probably not as good an idea in Java, since it’s hard to just build a hash on the fly.
  • Value of self calls which we assume will be overridden.
  • Strategy for refactoring when you realize that you need a new superclass. (E.g., I’m building B. B’s look like Eights. But there are some differences and neither is naturally a subclass of the other.)
    • Put nothing in the superclass.
    • Look for things that are common to the two subclasses and move them up.
    • Be cautious about promoting fields/methods to superclass.

Useful Metz example

class Bicycle
  attr_reader :size, :chain, :tire_size

  def initialize(args={})
    @size       = args[:size]
    @chain      = args[:chain]      || default_chain
    @tire_size  = args[:tire_size]  || default_tire_size

  def post_initialize(args)

  def spares
    { tire_size: tire_size,
      chain:     chain}.merge(local_spares)

  def local_spares

  def default_chain

  def default_tire_size
    raise NotImplementedError

class RoadBike < Bicycle
  attr_reader :tape_color

  def post_initialize(args)
    @tape_color = args[:tape_color]

  def local_spares
    {tape_color: tape_color}

  def default_tire_size

road_bike =
              size:       'M',
              tire_size:  25,
              tape_color: 'red' )
# -> {:tire_size   => 25,
#     :chain       => "10-speed",
#     :tape_color  => "red"}

Continuing Metz

  • We will do chapter 7
  • And then stop there.
  • Next semester, we’ll try to do the Metz material earlier.

Work time