OOPSLA 04 Educators Symposium - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

OOPSLA 04 Educators Symposium

Description:

How do we make a shape? Constructor for a rectangle: public ... Can specify a clear definition of a factory: we know how to make factories. Rice University ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 13
Provided by: Eri746
Category:

less

Transcript and Presenter's Notes

Title: OOPSLA 04 Educators Symposium


1
OOPSLA 04 Educators Symposium
  • Nifty Assignment The Shape Calculator

Eric Cheng, Dung Zung Nguyen, Mathias Ricken,
Stephen Wong
2
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!

3
What is a shape?
4
What is a shape?
  • Knows how to compute its area
  • Knows how to present itself visually

5
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?
6
Factory design pattern
  • Factories know how.
  • Can specify a clear definition of a factory we
    know how to make factories.

7
Behavioral definitions
  • IShapeFactory
  • JPanel getPropertyPanel()
  • IShape makeShape()
  • IShape
  • double getArea()
  • void paint(Graphics g, int x, int y)

8
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

9
Philosophical / Design Question
  • Should the shape know about, or even have the
    factory?

10
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.

11
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

12
Questions?
Write a Comment
User Comments (0)
About PowerShow.com