DOC PREVIEW
Duke CPS 108 - Model, View, Controller: battleship

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Software Design8.1Model, View, Controller: battleshipz Who does what, where are responsibilities in MVC?¾ This is a pattern, so there's isn't "one right way"z Model encapsulates state and behavior for game¾ Holds boards, interprets shots, game over, …¾ What other behavior responsibilities?¾ When model changes, it notifies the viewz View shows boards, accepts mouse and other input¾ These inputs must be forwarded to model, how?¾ Sometimes via controller, often view/controller sameSoftware Design8.2How do we use a view?z The view knows about model (controller in battleship)¾ In battleship.cpp, view constructed with the modelz The model (controller) knows about the view¾ Why can't this happen at model construction time?¾ How does this happen in battleship.cpp?¾ What are alternatives (what if client-code "forgets"?)z Hollywood principle for OO/MVC¾ Don't call us, we'll call you¾ The view calls the model when things happen¾ The model reacts and updates the view, repeatSoftware Design8.3Sequence Diagramz Function calls over timez Click is mapped to call¾ Model called¾ Mouse->board coordz Model interprets shot¾ Responds to view¾ What happens next?z How is "turn-taking" enforced¾ Shot already taken?¾ Next player to move?¾ Other possibilities?Software Design8.4Separate control/model?z Typically the control is not associated with the model¾ What is the model for battleship? Boards? Players?¾ Why is a separate control a good idea?z Toward network play¾ What does the controller do? Player interpretation?¾ Player x "goes", what happens next?¾ What are responsibilities of player?¾ What sequence of calls envisionedz What is right interface for model? For Controller?¾ How do they know about each other? Associations?Software Design8.5Placing Shipsz How are rules for placing ships enforced?¾ What happens in current version?¾ Who is responsible for constraints on placement?¾ How do we allow for alternative scenarios?z Strategy Design Pattern useful when:¾ Need variants of an algorithm¾ Clients shouldn't know about algorithm¾ Configure class with different behaviorsz What does ShipPlacementStrategy need?¾ How to determine if a ship placement is ok?Software Design8.6How does Strategy access ships?z Model can pass all ships to strategy¾ What does strategy really need to determine if a placement is ok?¾ Just ships? Other data?z Model can pass itself to strategy¾ Why might this be better? ¾ Downside to passing the model?z Worth doing in battleship example?Software Design8.7Dummy model/controllerz See pingcontroller.cpp¾ Echo/ping controller to show how MVC worksz Simple version of a model that echos commands¾ Shot at? Here's the shot¾ Ship placed? Here's the shipz How do alternate play?¾ Where are players?¾ Other


View Full Document

Duke CPS 108 - Model, View, Controller: battleship

Download Model, View, Controller: battleship
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Model, View, Controller: battleship and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Model, View, Controller: battleship 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?