OOPSLA ’04 Educator’s Symposium Nifty Assignment: The Shape Calculator Fix the link; fix code to close the window w/o AFrame Demo (3) Make the font bigger Big buttons Triangle factory w/ 3 points – write code, compile at runtime, load Get students’ solutions (for each part) from last semester Explain the assignment Must have demo in binary with some shapes for student to work with Makes clear of the functionality requirements Break into 4 parts and 4 directories; grade one piece at a time Why is it so nifty? Eric Cheng, Dung Zung Nguyen, Mathias Ricken, Stephen Wong Rice University
Niftiness Swing GUI application with the MVC pattern. Closures via anonymous inner class Callback architecture Extensibility and security via factories Dynamic nature of OO programs Abstraction! Rice University
What is a shape? Rice University
What is a shape? Knows how to compute its area Knows how to present itself visually Rice University
How do we make a shape? Constructor for a rectangle: public Rect(double width, double height) Constructor for a circle: public Circle(double radius) … How to call a constructor if its parameters are unknown? Rice University
Factory design pattern Factories know how. Can specify a clear definition of a factory: we know how to make factories. Rice University
Behavioral definitions IShapeFactory JPanel getPropertyPanel() IShape makeShape() IShape double getArea() void paint(Graphics g, int x, int y) Move IShape next to “what’s a shape?” Pop up UML or code of the IShape interfrace Move IShapeFactory as well. Rice University
Behavioral definitions Interfaces define behaviors. A factory is a factory if it satisfies the protocols; a shape is a shape if it complies to our definition. No need to have explicit class definitions. Closures Can have not only area, but also colors! Dynamically load code at runtime Delete this. Rice University
Philosophical / Design Question Should the shape know about, or even have the factory? Rice University
GUI builders for IDEs Rely on zero-ary public constructors for components. Breaks encapsulation. Violates definition of the component (is a shape a factory?) Can possibly break the system by creating an “immature”, but perfectly legal shape. Rice University
Our goal The clear distinction and separation of responsibilities Each piece of component does what it is meant to do, and expose the appropriate amount of information Rice University
Questions? Rice University