Lecture 07: Ballworld Design

Ambient Temperature: 73.8oF

Concepts

  1. Separating the Invariant from the Variant.
    1. “Invariant” properties (and methods) live in the (abstract) superclass. Anything you put in AShape must satisfy the statement “All shapes everywhere forever have a ________.”
    2. Things that can be invariant include (but are not necessarily limited to) a method’s presence, a field’s presence, a method’s implementation, and a field’s value.
    3. Write programs targeting the Invariant (‘s interface), so that your programs can work with any, all, and arbitrary variants, including ones you may not have ever dreamed of.
  2. Objects have behavior, which you experience when you interact with them, and a construction, which is how they’re built. When objects interact with each other in Java, they should only care about the behavior, not the underlying construction or data. Therefore, any object whose behaviors include “all of the things a duck can do” (for example) can be treated as a duck (for example) by other Java objects. Moral: Use Interfaces.
  3. Concrete methods are rarely overridden, because that’s not what overriding is really for: If a child class is fundamentally changing the behavior, you’re probably doing it wrong.
  4. Drive-by incidental introduction to “hey you can use wildcards in Java Generics.” Hand-waving ensued.
  5. Observer-Observable design pattern will be necessary in Homework 2.
  6. There are 32 different types of bridges, if you don’t count sub-types. Source: http://en.wikipedia.org/wiki/List_of_bridge_types

Quotes

  1. “(paraphrased) What if I took some fluid and put it inside my duck robot so that when you stuck a needle in and drew it out, it contained DNA that perfectly matched your duck? Is that a duck?” – Dr. Wong
  2. “Why isn’t there a bridge that swoops through the world and expresses the angst of society?” – Dr. Wong

Resources

  1. Lecture Webpage: http://www.clear.rice.edu/comp310/f12/lectures/lec07/
  2. Hipster Flipbook on YouToube: http://www.youtube.com/watch?v=4B3vNE459CQ
  3. Wildcards in Java Generics: http://docs.oracle.com/javase/tutorial/extra/generics/wildcards.html


One Response to “Lecture 07: Ballworld Design”

  1.   jra6 Says:

    I would argue that the Duck-typing reference is extremely inappropriate for a class discussing design patterns in Java. Even if a class implements

    quack()

    and

    breedWithLiveDuck()

    , Java won’t recognize it as a duck if it doesn’t explicitly declare ahead of time that it is, indeed, a duck.

    This type of reasoning is much more apt in, say, a discussion about python’s type system.