Creating Sequence Diagrams

 < Day Day Up > 



Iterating Through the Design Process

At this point in the design process you will begin to iterate through the process of adding classes to design diagrams and defining any necessary functions and attributes. You might very well start generating code for the classes you have created thus far to test the quality of the automatically generated code and see how things are going to turn out. Following my earlier advice of 'design a little, program a little, test a lot', I recommend this approach and advise you not to wait until you have designed everything up front to test the quality of the generated code.

In this section I will provide you with a table that lists all the classes I created in my version of the robot rat project, their functions, and their attributes. I will also show you the final overall class diagram. I will postpone the formal discussion of code generation until after the section on sequence diagrams.

Table 20-3 lists the classes used in the robot rat project along with their package affiliation, attributes, and functions.

Table 20-3: Robot Rat Project Classes

Class Name
(Type)

Package

Attributes

Functions

AbstractControlledObject
(Abstract)

[Header File Only]

Remote Controlled Object

None

+AbsractControlledObject(){}

+virtual ~AbstractControlledObject(){}

+virtual void move(int spaces)=0

+virtual void turnLeft()=0

+virtual void turnRight()=0

+virtual void setBoundaries(int rows, int columns)=0

+virtualvoid setRow(int row)=0

+virtual void setColumn(int column)=0

+virtual void setPosition(int row, int column)=0

+virtual int getRow()=0

+virtual int getColumn()=0

+virtual int getUpperRowBoundary()=0

+virtual int getUpperColumnBoundary()=0

+virtual void setMarkerUp()=0

+virtual void setMarkerDown()=0

+virtual void toggleMarker()=0

+virtual bool isMarkerDown()=0

+virtual char* getObjectType()=0

AbstractPosition

(Abstract)

[Header File Only]

Remote Controlled Object

None

+AbstractPosition(){}

+virtual ~AbstractPosition(){}

+virtual void move(int spaces)=0

+virtual void turnLeft()=0

+virtual void turnRight()=0

+virtual void setBoundaries(int rows, int columns)=0

+virtualvoid setRow(int row)=0

+virtual void setColumn(int column)=0

+virtual void setPosition(int row, int column)=0

+virtual int getRow()=0

+virtual int getColumn()=0

+virtual int getUpperRowBoundary()=0

+virtual int getUpperColumnBoundary()=0

AbstractMarker

(Abstract)

[Header File Only]

Remote Controlled Object

None

+AbstractMarker(){}

+virtual ~AbstractMarker(){}

+virtual void setMarkerUp()=0

+virtual void setMarkerDown()=0

+virtual void toggleMarker()=0

+virtual bool isMarkerDown()=0

RemoteControlledObject

(Abstract)

[It does not implement the char* getObjectType() function]

Remote Controlled Object

-static int count

-AbstractPosition* itsPosition

-AbstractMarker* itsMarker

+RemoteControlledObject()

+virtual ~RemoteControlledObject()

+void move(int spaces)

+void turnLeft()

+void turnRight()

+void setBoundaries(int rows, int columns)

+void setRow(int row)

+void setColumn(int column)

+void setPosition(int row, int column)

+int getRow()

+int getColumn()

+int getUpperRowBoundary()

+int getUpperColumnBoundary()

+void setMarkerUp()

+void setMarkerDown()

+void toggleMarker()

+bool isMarkerDown()

Position

(Concrete)

Remote Controlled Object

-int its_row

-int its_column

-int upper_row_boundary

-int upper_column_boundary

-int lower_row_boundary

-int lower_column_boundary

-enum Direction {NORTH, SOUTH, EAST, WEST}

-Direction its_direction

+Position(int row = 0, int column = 0)

+~Position()

+ void move(int spaces)=0

+ void turnLeft()=0

+void turnRight()=0

+void setBoundaries(int rows, int columns)=0

+void setRow(int row)=0

+void setColumn(int column)=0

+void setPosition(int row, int column)=0

+int getRow()=0

+int getColumn()=0

+int getUpperRowBoundary()=0

+int getUpperColumnBoundary()=0

-void incrementRow(int val)

-void incrementColumn(int val)

-void setLowerRowBoundary(int lower)

-void setUpperRowBoundary(int upper)

-void setLowerColumnBoundary(int lower)

-void setUpperColumnBoundary(int upper)

Marker

(Concrete)

Remote Controlled Object

-enum MarkerPosition {UP, DOWN}

-MarkerPosition its_marker_position

+Marker()

+virtual ~Marker()

+void setmarkerUp()

+void setMarkerDown()

+void toggleMarker()

+bool isMarkerDown()

AbstractControlledRodent

(Abstract)

[Header File Only]

Rodent

None

+AbstractControlledRodent(){}

+virtual ~AbstractControlledRodent(){}

+virtual void setTailUp() = 0

+virtual void setTailDown() = 0;

RobotRat

(Concrete)

Rodent

None

+RobotRat(int row_boundary = 20,

                 int column_boundary = 20)

+virtual ~RobotRat()

+RobotRat(RobotRat& rhs)

+RobotRat& operator=(RobotRat& rhs)

+void setTailUp()

+void setTailDown()

+char* getObjectType()

RodentWorld

(Concrete)

Rodent World

- AbstractControlledRodent**

            rodent_array

-int its_rows

-int its_columns

-int number_or_rodents

-int rodent_number

+RodentWorld(int rows = 20, int columns = 20)

+virtual ~RodentWorld()

+void addRodent()

+void deleteRodent()

+void toggleRodent();

+void turnRodentLeft()

+void turnRodentRight()

+void moveRodent(int spaces)

+void setRodentTailUp()

+void setRodentTailDown()

+char* getRodentType()

+int getRodentRow()

+int getRodentColumn()

+bool isRodentTailDown()

Controller

(Concrete)

Controller

-UserInterface* its_ui

-RodentWorld* its_world

-enum MenuActions {ADD = 1, TOGGLE, TURNRIGHT, TURNLEFT, TAILUP, TAILDOWN, MOVE, DISPLAYFLOOR, EXIT}

-void move()

+Controller()

+~Controller()

+void run()

UserInterface

(Concrete)

User

Interface

-bool** floor

-int its_rows

-int its_columns

-int spaces

+UserInterface()

+~UserInterface()

+void displayMenu()

+int getMenuChoice()

+void markFloor(int row, int column)

+void clearFloor(int row, int column)

+displayFloor()

+int getRows()

+int getColumns()

+int getSpaces()

The completed overall class diagram is given in figure 20-18.

click to expand
Figure 20-18: Completed and Annotated Overall Class Diagram

The overall class diagram gives a high-level view of the robot rat project classes and their static relationships. At this point in the design process you would continue to iterate through the steps of selecting a class and adding attributes and functions.

A suggested approach is to concentrate on the classes in a particular package, getting all their attributes and functions defined. For example, a good place to start would be the classes in the Remote Controlled Object package. What you will notice as you iterate through your design is that the design will be unstable. By this I mean you will find yourself making changes to almost all the classes in the RemoteControlledObject package as you begin to better understand the needs and issues surrounding the design. Since subclasses in an inheritance hierarchy depend on their base classes, you will find that changes to base classes have a definite effect on dependent subclasses. For example, if you add a pure virtual method to a base class you must then implement that function in a subclass somewhere down the line. However, as the design progresses, the abstractions at the upper levels of the design will begin to stabilize. Soon enough you will reach a point where the necessity to modify the high-level abstractions drops way off. The design begins to set like Jello™ and adding functionality becomes a simple matter of extending the design. (see chapter 19 for a discussion of the open-closed principle)



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net