Presentation is loading. Please wait.

Presentation is loading. Please wait.

Design Patterns for Marine Biology Simulation Dung “Zung” Nguyen Mathias Ricken Stephen Wong Rice University.

Similar presentations


Presentation on theme: "Design Patterns for Marine Biology Simulation Dung “Zung” Nguyen Mathias Ricken Stephen Wong Rice University."— Presentation transcript:

1 Design Patterns for Marine Biology Simulation Dung “Zung” Nguyen Mathias Ricken Stephen Wong Rice University

2 AP Marine Biology Simulation Unenforceable contracts Insecure architecture a few pitfalls... Key issue: Limited extensibility Replicated data Tight Coupling

3 Where am I? Latitude = 29.65 Longitude = 95.28 On some global coordinate grid? Do I know my own coordinates? Does anyone else know my coordinates? Should I know anyone else’s coordinates? Do I really care where Greenwhich is? Think Simple. I know where I am: right here. X X Which is not the same as here. X And not the same as here either.

4 Each fish has its own local environment X X X X X The local environment is an indirection layer between the fish and the global environment.

5 Fish and their Environment A fish has a local environment The local environment provides services to the fish The local environment does NOT provide x-y coordinates! The local environment is instantiated by the global environment Factory Method Design Pattern Local environment communicates with global environment but fish do not.

6 A Fish’s Dilemma Unblocked!Blocked! Can I move forward? Send a message to the local environment! Blocked case command Unblocked case command Send commands to local environment The appropriate command is selected The fish responds accordingly! X

7 Or… The appropriate command is selected Local environment makes a move command Move command sent to fish If desired, fish applies move command A fish does not need to know its x-y coordinate! A fish does not need to know “how” to move! A fish is decoupled from the global environment! Move Command Unblocked! Blocked! X A fish can ONLY move as prescribed by its environment!

8 Fish-Environment Interaction _localEnv.tryMoveFwd(this,, ); SimpleFish Class new ILambda() { public Object apply(Object moveCmd) { ((ILambda)moveCmd).apply(null); return null; } } Command to execute if blocked Command to execute if unblocked new ILambda() { public Object apply(Object notUsed) { turnRight(Math.PI); return null; } Delegate to the local environment

9 Fish-Environment Interaction public Object tryMoveFwd(AFish f, ILambda blocked, ILambda unblocked) { ILocalEnv le = makeMoveFwdLocalEnv(); return le.execute(new ILocalEnvVisitor() { public Object emptyCase(ILocalEnv h, Object nu) { ILambda moveCmd = new MoveLambda(le); return unblocked.apply(moveCmd); } public Object nonEmptyCase(ILocalEnv h, Object nu) { return blocked.apply(null); } }, null); } LocalEnvironment Class Make local environment in the direction the fish wants to move … either make a command that actually moves the fish… Depending on whether the new local environment is empty or not… … and execute the unblocked command … or execute the blocked command

10 Design Patterns for Decoupling MVC Decouples a model from its view OBSERVER-OBSERVABLE Decouples sender and multiple receivers VISITOR Decouples structure and its behaviors. FACTORY Decouples framework from object creation COMMAND Decouples decisions from actions. COMPOSITE Decouples a whole from its parts. INTEGRAL COMPONENTS OF A UNIFIED PEDAGOGY

11 The Culmination of a Unified OO Pedagogy Abstract Structure and Behavior Polymorphism Design Patterns Unit Tests MBS ~ end of 2 nd semester.

12 Studying the Case Study SimpleFish UnboundedEnv Variant Fish Behavior Variant Environment Behavior Re-implement as per given specs. White-box Framework: Extension by Subclassing

13 Inheritance vs. Composition Strategy Pattern + void move() Static Behavior! Separate the variants from the invariants

14 Comparative study vs. APMBS  Replaceable environments  Robustness  Security Enhanced capabilities Abstracted, decoupled design

15 Is it really about Fish? ! ! ! Design patterns are expressions of recurring abstractions that embody fundamental computing principles Learning to abstract the problems at hand and master their complexity Design patterns are “tangible abstractions” Design patterns empower students to design software that is correct, flexible, extensible and robust. It’s all about Abstraction! Why design patterns?

16 For more information:  http://www.exciton.cs.rice.edu/research/SIGCSE04/ http://www.exciton.cs.rice.edu/research/SIGCSE04/  To download code files: –Username: sigcse04 –Password: ricembs  E-mail: –dxnguyen@rice.edu dxnguyen@rice.edu –mgricken@rice.edu mgricken@rice.edu –swong@rice.edu swong@rice.edu

17 User-Environment Interaction public ILambda makeEditCmd(Point p, IFishFactory factory) { final ILocalEnv le = makeLocalEnv(p); return (ILambda)le.execute(new ILocalEnvVisitor() { public Object emptyCase(ILocalEnv h, Object nu) { return addFish(localEnv, factory.createFish()); } public Object nonEmptyCase(ILocalEnv h, Object nu) { return editFish(host); } }, null); } AGlobalEnv Class Make local environment for the location of the mouse click … either add a fish there using the factory Depending on whether the new local environment is empty or not… … or edit the fish’s local environment


Download ppt "Design Patterns for Marine Biology Simulation Dung “Zung” Nguyen Mathias Ricken Stephen Wong Rice University."

Similar presentations


Ads by Google