110 likes | 204 Views
CS 190M Introduction to Programming with Concurrency Lecture: 4. September 8, 2008 Class and Sequence Diagrams Aditya Mathur. Objectives. Learn about: Incremental development Modifying a design to include new requirements. Reading: Textbook: Chapter 5.1, 5.2, 5.3.
E N D
CS 190M Introduction to Programming with ConcurrencyLecture: 4. September 8, 2008Class and Sequence DiagramsAditya Mathur CS 190M. Lecture 4.
Objectives • Learn about: • Incremental development • Modifying a design to include new requirements Reading: Textbook: Chapter 5.1, 5.2, 5.3 CS 190M. Lecture 4.
Recall: First increment: RobotFunOne • Simulate the movement of a single robot. • The robot accepts the following move commands: • S(traight) • B(ackwards) • L(eft) • R(ight) • Use the E(xit) command to exit from the simulato • Additional commands: • F: Sound OFF • N: Sound ON CS 190M. Lecture 4.
Second increment: RobotFunTwo • Simulate the movement of a single robot. • Ensure that it does not collide with the surrounding walls • Robot is initially placed in a square room. Q: Which parts of the design/code need modification? CS 190M. Lecture 4.
attributes Robot RobotFunOne positionX: int positionY: int name: String <<create>> moveRobot getCommand main <<call>> operations Robot getPosX getPosY move <<call>> RobotSounds playClip Recall: Classes in RobotFunOne A class diagram helps (a) enumerate classes used in your program and (b) specify how these classes relate to each other. CS 190M. Lecture 4.
attributes Robot RobotFunTwo positionX: int positionY: int name: String <<create>> moveRobot getCommand main <<call>> operations Robot getPosX getPosY move collision <<call>> RobotSounds playClip Classes in RobotFunTwo Recall: A class diagram helps (a) enumerate classes used in your program and (b) specify how these classes relate to each other. CS 190M. Lecture 4.
aRobot: Robot :RobotFunOne Create a robot start aRobot getCommand loop move Generate sound getCommand :RobotSounds Display goodbye Message and exit Recall: Behavior of RobotFunOne [command!=‘E’] CS 190M. Lecture 4.
aRobot: Robot :RobotFunTwo Create a robot start aRobot getCommand [Collision not possible?] loop alt move Generate sound getCommand :RobotSounds Display goodbye Message and exit Behavior of RobotFunTwo [command!=‘E’] CS 190M. Lecture 4.
Third increment: RobotFunThree • Simulate the movement of a single robot. • Ensure that it does not collide with the surrounding walls • Robot is initially placed in a square room. • Robot can move along any direction--specified by an angle in degrees. • Robot can move in multiple integral steps. • Commands: • M angle steps (e.g. M 45 3 to move three steps along 45 degrees) • E: Exit Q: Which parts of the design/code need modification? CS 190M. Lecture 4.
RobotFunThree Robot command: char angle: double steps: int positionX: int positionY: int name: String <<create>> moveRobot getCommand main <<call>> Robot getPosX getPosY move collision V Generalization <<call>> AdvancedRobot RobotSounds advancedRobot move collision playClip Classes in RobotFunThree CS 190M. Lecture 4.
king: AdvancedRobot :RobotFunThree Create a robot start king getCommand Collision not possible? loop alt move (angle, steps) Generate sound getCommand :RobotSounds Display goodbye Message and exit Behavior of RobotFunTwo command!=‘E’ CS 190M. Lecture 4.