User:BenMcDonald
BenMcDonald (Talk | contribs) m |
BenMcDonald (Talk | contribs) |
||
Line 34: | Line 34: | ||
[[Image:BenM's UMLI3.png|border|1000px]] | [[Image:BenM's UMLI3.png|border|1000px]] | ||
− | Maxims | + | ===Maxims=== |
* [[Command query separation]] / [[Avoid side effects]] - The interface would be tidier if the getFeedback() method in the Trainer object also cleared the feedback but doing this would violate CQS. By have two methods, getFeedback() and clearFeedback(), there are no side effects and the status of the object can be queried without invoking any commands. Additionally, I could add a getAndClearFeedback() method for convenience. One plus of C++ is that you can mark queries, and enforce them, with the const keyword. | * [[Command query separation]] / [[Avoid side effects]] - The interface would be tidier if the getFeedback() method in the Trainer object also cleared the feedback but doing this would violate CQS. By have two methods, getFeedback() and clearFeedback(), there are no side effects and the status of the object can be queried without invoking any commands. Additionally, I could add a getAndClearFeedback() method for convenience. One plus of C++ is that you can mark queries, and enforce them, with the const keyword. | ||
* [[Design by contract]] - Using assert's to enforce conditions at the moment | * [[Design by contract]] - Using assert's to enforce conditions at the moment | ||
* [[Don't expose mutable attributes]] - In C++, objects returned from another object's method can be marked as const to make them immutable. | * [[Don't expose mutable attributes]] - In C++, objects returned from another object's method can be marked as const to make them immutable. | ||
* [[Object Encapsulation]] - Variables are ether 'protected' or 'public' and all methods are marked 'virtual'. Object encapsulation is more intuitive and I did not find any appropriate place for private variables. Class encapsulation does not allow for effective unit testing through inheritance. | * [[Object Encapsulation]] - Variables are ether 'protected' or 'public' and all methods are marked 'virtual'. Object encapsulation is more intuitive and I did not find any appropriate place for private variables. Class encapsulation does not allow for effective unit testing through inheritance. | ||
+ | * [[Getters and setters]] - Tried to model behaviour in objects but could not avoid a long get/set list on my data objects when I seperated them out with the observer pattern -- Pose, BoxingPose and UserBoxerPose. | ||
− | + | ||
+ | ===Some C++ Language semantics avoided in this project design=== | ||
* [[Object Encapsulation|Public and private attributes]] | * [[Object Encapsulation|Public and private attributes]] | ||
* [[Don't expose mutable attributes|Exposing mutable attributes]] | * [[Don't expose mutable attributes|Exposing mutable attributes]] | ||
Line 49: | Line 51: | ||
** Overloaded methods may be called | ** Overloaded methods may be called | ||
* Non public inheritance | * Non public inheritance | ||
− | |||
=== Patterns === | === Patterns === | ||
Line 58: | Line 59: | ||
| Hierarchy One|| ''BoxerPose '' | | Hierarchy One|| ''BoxerPose '' | ||
|- | |- | ||
− | | Hierarchy Two || ''Boxer '' | + | | Hierarchy Two || ''Boxer'' |
|- | |- | ||
| Abstract accessor || ''Boxer.getPose() '' | | Abstract accessor || ''Boxer.getPose() '' | ||
|- | |- | ||
|} | |} | ||
− | + | I wanted to have some sort of contract in the Boxer object about having a BoxerPose so I could access a known Boxer object's BoxerPose. The solution to this was an abstract accessor in Boxer. | |
− | const TrainerPose *trainerPose = dynamic_cast< TrainerPose | + | A problem with using an abstract accessor in C++ is that method returns cannot be overrided so any calls to getPose in derived objects had to be cast. |
+ | |||
+ | const TrainerPose *trainerPose = dynamic_cast< const TrainerPose *>(trainer.getPose()); | ||
Line 88: | Line 91: | ||
| Element || Boxer | | Element || Boxer | ||
|- | |- | ||
− | | Visitor || | + | | Visitor || SerializerVisitor |
+ | |- | ||
+ | | ConcreteVisitor || XMLVisitor | ||
|- | |- | ||
|} | |} | ||
Line 104: | Line 109: | ||
|- | |- | ||
|} | |} | ||
− | A trainer can be made to observe a UserBoxerPose. The trainer will record the pose history and generate evaluations from that history, generate feedback from its observations and react to the pose's actions. | + | A trainer can be made to observe a UserBoxerPose. The trainer will record the pose history and generate evaluations from that history, generate feedback from its observations and react to the pose's actions. It is behaviorally complete to have a boxer's pose Observable. |
[[Observer|Observer Pattern]] | [[Observer|Observer Pattern]] | ||
Line 126: | Line 131: | ||
* Notifies views of changes | * Notifies views of changes | ||
− | View - TrainerAnimation | + | View - TrainerAnimation, osgVideo |
* Renders a model | * Renders a model | ||
* Requests updates from a model | * Requests updates from a model |
Revision as of 03:23, 2 October 2009
Contents |
Ben McDoanld's page
I am doing my design study for my COSC426:Augmented Reality project. I need a design for a boxing skills trainer. No code has been written so far. I have made a sketch of the requirements for the design of the software. The project is in C++ using the libraries open scene graph (osg), augmented reality tool-kit open scene graph (ARTosg) and the Wii controller library for windows
Requirements:
- A score needs to be generated from a set of tested skills:
- Consistent guard
- Eyes forward and on opponent
- Bobbing and weaving
- Timing of punches
- Each skill needs to be modeled and the evaluation method for each skill also needs to be modeled.
- The performance on the skills needs to be evaluated and for additional activities to be recommended to the athlete.
- An athlete’s evaluation history, progress and general details to be recorded and recoverable.
- Measurements from the augmented reality marker need to update the position of the athlete's head.
- WiiMote gestures need to be detected and reacted to.
My design is below. Any comments or suggestions are very welcome.
Iteration Three
Style
Standard | Code | UML |
Immutable attributes accessors are named after the attributes as is the C++ standard | Object foo_; virtual const Object& foo() const; | foo, foo() |
Object queries end with the keyword 'const' | virtual const std::string& name() const; | name():String const |
Method inputs begin with the keyword 'const' | virtual void foo(const string &in, string *out); | foo(const String in):String |
Maxims
- Command query separation / Avoid side effects - The interface would be tidier if the getFeedback() method in the Trainer object also cleared the feedback but doing this would violate CQS. By have two methods, getFeedback() and clearFeedback(), there are no side effects and the status of the object can be queried without invoking any commands. Additionally, I could add a getAndClearFeedback() method for convenience. One plus of C++ is that you can mark queries, and enforce them, with the const keyword.
- Design by contract - Using assert's to enforce conditions at the moment
- Don't expose mutable attributes - In C++, objects returned from another object's method can be marked as const to make them immutable.
- Object Encapsulation - Variables are ether 'protected' or 'public' and all methods are marked 'virtual'. Object encapsulation is more intuitive and I did not find any appropriate place for private variables. Class encapsulation does not allow for effective unit testing through inheritance.
- Getters and setters - Tried to model behaviour in objects but could not avoid a long get/set list on my data objects when I seperated them out with the observer pattern -- Pose, BoxingPose and UserBoxerPose.
Some C++ Language semantics avoided in this project design
- Public and private attributes
- Exposing mutable attributes
- Non virtual methods
- Calling methods in constructors - init() methods used instead
- Hard to account for errors
- Constructors cannot fail
- Overloaded methods may be called
- Non public inheritance
Patterns
Parallel hierarchies problem solution... Intelligent children pattern
Hierarchy One | BoxerPose |
Hierarchy Two | Boxer |
Abstract accessor | Boxer.getPose() |
I wanted to have some sort of contract in the Boxer object about having a BoxerPose so I could access a known Boxer object's BoxerPose. The solution to this was an abstract accessor in Boxer.
A problem with using an abstract accessor in C++ is that method returns cannot be overrided so any calls to getPose in derived objects had to be cast.
const TrainerPose *trainerPose = dynamic_cast< const TrainerPose *>(trainer.getPose());
Context | Trainer |
Abstract State | TrainingActivity |
Concrete State1 | PunchingDrill |
Concrete State2 | BobbingAndWeaving |
ConcreteElement | Trainer, Boxer |
Element | Boxer |
Visitor | SerializerVisitor |
ConcreteVisitor | XMLVisitor |
Subject | BoxerPose |
ConcreteSubject | UserBoxerPose |
Observer | Observer |
ConcreteObserver | Trainer |
A trainer can be made to observe a UserBoxerPose. The trainer will record the pose history and generate evaluations from that history, generate feedback from its observations and react to the pose's actions. It is behaviorally complete to have a boxer's pose Observable.
Subject | BoxerPose |
ConcreteSubject | TrainerPose |
Observer | Observer |
ConcreteObserver | TrainerAnimation |
I wanted the Trainer to know about the timings of the animations and was tempted to couple the Trainer class to the TrainerAnimations class and vice versa. I instead decided to remove the Trainer's knowledge of its animations and required the animations to conform to the timings of the Trainer's movements. The TrainerAnimations class is likely to change and coupling the Trainer class to it would increase maintenance of the Trainer class.
MVC
Models - BoxerPose, UserBoxerPose and TrainerPose
- Respond to state queries
- Stores application state
- Notifies views of changes
View - TrainerAnimation, osgVideo
- Renders a model
- Requests updates from a model
- Allows controller to select view
Controller - BoxingTrainer
- Defines application behaviour
- Selects view for response
Iteration Two
Design:
- Context - Trainer
- State - TrainingState
- ConcreteStates - PunchingDrill, BobbingAndWeaving
- Subject - Observable
- ConcreteSubject - UserBoxer
- Observer - Observer
- ConcreteObserver - Trainer
- Subject - Observable
- ConcreteSubject - Trainer
- Observer - Observer
- ConcreteObserver - TrainerAnimation
Iteration One
Design:
- Subject - Observable
- ConcreteSubject - Athlete
- Observer - Observer
- ConcreteObserver - Trainer