Object Oriented Design Terminology - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Object Oriented Design Terminology

Description:

Moving a FilledRect is analogous to turning a car. 8/15/09. Cosc 200 Programming Techniques ... Describe the program in words and pictures ... – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 22
Provided by: davidh127
Category:

less

Transcript and Presenter's Notes

Title: Object Oriented Design Terminology


1
Object Oriented Design Terminology
  • A class is a textual description of a collection
    of similar objects.
  • A class is what we type into JCreator.
  • We can see classes, read them, and write them.
  • They exist even when our program is not running.
  • They consist of a collection of variable and
    method definitions.
  • An object is an instance of a class that exists
    during runtime.
  • It is what we get back when we call a constructor
    and what we manipulate with method calls.
  • If a class is a cookie cutter, then objects are
    cookies.
  • If you and I are objects, we belong to the class
    of humans.
  • A class may generate many objects Snowflake,
    Vehicle, MovingBall.
  • A class may generate only one object
    WindowController classes.
  • A class provides an abstraction in our program.
  • We can use a class without knowing how it is
    implemented.
  • Moving a FilledRect is analogous to turning a car.

2
Object Oriented Design Methodology
  • You are asked to write a program.
  • Describe the program in words and pictures.
  • Identify the objects (nouns) to be modeled .
  • List the properties (adjectives) and behaviors
    (verbs) of each type of object.
  • Model properties with instance variables.
  • Model behaviors with methods.
  • After the design is completed, implement methods
    incrementally.
  • For example, consider FunWithStars.
  • Continue to view the demo for reference as I go
    through these slides.

3
Describe the program in words and pictures
  • A star consists of equally spaced and equal
    length rays emanating from a central point.
  • The user can press, drag, and release the mouse
    to either create a new star or to select and drag
    a star that is already created.
  • The user can click on an already created star to
    start or speed up its rotation.
  • These user actions will be slowly and
    continuously reversed while the mouse is removed
    from the applet.

4
Identify the objects (nouns) to be modeled
  • A star consists of equally spaced and equal
    length rays emanating from a central point.
  • The user can press, drag, and release the mouse
    to either create a new star or to select and drag
    a star that is already created.
  • The user can click on an already created star to
    start or speed up its rotation.
  • These user actions will be slowly and
    continuously reversed while the mouse is removed
    from the applet.

5
Identify the objects (nouns) to be modeled
  • A star consists of equally spaced and equal
    length rays emanating from a central point.
  • The user can press, drag, and release the mouse
    to either create a new star or to select and drag
    a star that is already created.
  • The user can click on an already created star to
    start or speed up its rotation.
  • These user actions will be slowly and
    continuously reversed while the mouse is removed
    from the applet.

user, mouse, applet gtgt FunWithStars star gtgt
Star gtgt BunchOfStars user actions gtgt Action
gtgt (Create, Move, ChangeSpeed) gtgt History
6
List the properties and behaviors of FunWithStars
  • FunWithStars has
  • a bunch of stars
  • a history of user actions
  • FunWithStars can
  • be created
  • respond to mouse press
  • respond to mouse drag
  • respond to mouse release
  • respond to mouse click
  • respond to mouse exit
  • respond to mouse enter

7
Model properties with instance variables
  • FunWithStars instance variables
  • BunchOfStars bunch
  • History history
  • FunWithStars has
  • a bunch of stars
  • a history of user actions
  • FunWithStars can
  • be created
  • respond to mouse press
  • respond to mouse drag
  • respond to mouse release
  • respond to mouse click
  • respond to mouse exit
  • respond to mouse enter

8
Model behaviors with methods
  • FunWithStars instance variables
  • BunchOfStars bunch
  • History history
  • FunWithStars methods
  • begin()
  • onMousePress(Location point)
  • onMouseDrag(Location point)
  • onMouseRelease(Location point)
  • onMouseClick(Location point)
  • onMouseExit(Location point)
  • onMouseEnter(Location point)
  • FunWithStars has
  • a bunch of stars
  • a history of user actions
  • FunWithStars can
  • be created
  • respond to mouse press
  • respond to mouse drag
  • respond to mouse release
  • respond to mouse click
  • respond to mouse exit
  • respond to mouse enter

9
List the properties and behaviors of a Star
  • A Star has
  • rays
  • center
  • radius
  • color
  • speed of rotation
  • A Star can
  • be created
  • be removed from the canvas
  • move
  • rotate
  • change its radius
  • change its speed of rotation
  • change its color
  • check whether it contains a point

10
Model properties with instance variables
  • A Star has
  • rays
  • center
  • radius
  • color
  • speed of rotation
  • A Star can
  • be created
  • be removed from the canvas
  • move
  • rotate
  • change its radius
  • change its speed of rotation
  • change its color
  • check whether it contains a point
  • Star instance variables
  • Line ray
  • Location center
  • double radius
  • double speed

11
Model behaviors with methods
  • A Star has
  • rays
  • center
  • radius
  • color
  • speed of rotation
  • A Star can
  • be created
  • be removed from the canvas
  • move
  • rotate
  • change its radius
  • change its speed of rotation
  • change its color
  • check whether it contains a point
  • Star instance variables
  • Line ray
  • Location center
  • double radius
  • double speed
  • Star methods
  • Star(center, radius, points, canvas)
  • removeFromCanvas()
  • move(xOffset, yOffset)
  • run()
  • setRadius(radius)
  • changeSpeed(amount)
  • setColor(color)
  • boolean contains(point)

12
Model behaviors with methods
  • A Star has
  • rays
  • center
  • radius
  • color
  • speed of rotation
  • A Star can
  • be created
  • be removed from the canvas
  • move
  • rotate
  • change its radius
  • change its speed of rotation
  • change its color
  • check whether it contains a point
  • Star instance variables private
  • Line ray
  • Location center
  • double radius
  • double speed
  • Star methods public
  • Star(center, radius, points, canvas)
  • removeFromCanvas()
  • move(xOffset, yOffset)
  • run()
  • setRadius(radius)
  • changeSpeed(amount)
  • setColor(color)
  • boolean contains(point)

13
List the properties and behaviors of a
BunchOfStars
  • A BunchOfStars has
  • a sequence of stars
  • A BunchOfStars can
  • be created
  • have stars added to it
  • have stars removed from it
  • find one of its stars containing a point
  • report the number of stars it contains

14
Model properties with instance variables
  • A BunchOfStars has
  • a sequence of stars
  • A BunchOfStars can
  • be created
  • have stars added to it
  • have stars removed from it
  • find one of its stars containing a point
  • report the number of stars it contains
  • BunchOfStars instance variables
  • Star stars
  • int numStars

15
Model behaviors with methods
  • A BunchOfStars has
  • a sequence of stars
  • A BunchOfStars can
  • be created
  • have stars added to it
  • have stars removed from it
  • find one of its stars containing a point
  • report the number of stars it contains
  • BunchOfStars instance variables
  • Star stars
  • int numStars
  • A BunchOfStars methods
  • BunchOfStars()
  • add(star)
  • Star remove()
  • Star findStar(point)
  • int size()

16
List the properties and behaviors of an Action
  • An Action has
  • a type
  • create a star
  • move a star
  • change rotation speed of a star
  • An Action can
  • be created
  • undo itself

17
Model properties/behaviors with instance
variables/methods
  • An Action has
  • a type
  • create a star
  • move a star
  • change rotation speed of a star
  • An Action can
  • be created
  • undo itself
  • Action instance variable
  • String type
  • bundle, star
  • star, xOffset, yOffset
  • star. speedChange
  • Action methods
  • Action(type, ???)
  • void undo()
  • Instead . . .
  • use an interface, and
  • three classes implementing the interface.

18
Model properties/behaviors with instance
variables/methods
  • An Action has
  • a type
  • create a star
  • move a star
  • change rotation speed of a star
  • An Action can
  • be created
  • undo itself
  • Action method
  • void undo()
  • SpeedChange instance variables
  • Star star
  • double amount
  • Move instance variables
  • Star star
  • double xOffset
  • double yOffset
  • Create instance variable
  • BundleOfStars bundle
  • SpeedChange, Move, Create methods
  • constructors with appropriate parameters

19
List the properties and behaviors of a History
  • A History has
  • a sequence of user actions
  • A History can
  • be created
  • have user actions added to it
  • have user actions continuously undone and removed
    from it

20
Model properties/behaviors with instance
variables/methods
  • A History has
  • a sequence of user actions
  • A History can
  • be created
  • have user actions added to it
  • have user actions continuously undone and removed
    from it
  • History instance variables
  • Action actions
  • int numActions
  • History methods
  • History()
  • add(action)
  • startRewind()
  • stopRewind()
  • How to rewind?
  • Create an object of a class that extends
    ActiveObject.

21
Object Oriented Design Summary
  • Methodology
  • Describe the program in words and pictures.
  • Identify the objects (nouns) to be modeled .
  • List the properties (adjectives) and behaviors
    (verbs) of each type of object.
  • Model properties with instance variables.
  • Model behaviors with methods.
  • After the design is completed, implement methods
    incrementally.
  • . . . or in parallel with others in a team.
Write a Comment
User Comments (0)
About PowerShow.com