1 / 17

Design Patterns for Marine Biology Simulation

Design Patterns for Marine Biology Simulation. Dung “Zung” Nguyen Mathias Ricken Stephen Wong Rice University. Unenforceable contracts. Replicated data. Insecure architecture. Limited extensibility. AP Marine Biology Simulation. a few pitfalls. Key issue:. Tight Coupling.

badrani
Download Presentation

Design Patterns for Marine Biology Simulation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. Which is not the same as here. On some global coordinate grid? And not the same as here either. I know where I am: right here. Think Simple. Where am I? 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? To change my location is to change my LOCAL environment. Knowing my location does NOT mean I know my global coordinate! ? X X X Latitude = 29.65 Longitude = 95.28

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

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

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

  7. MoveCommand Local environment makes a move command Or… The appropriate command is selected 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! ? Decoupled, yet interactive behavior! A fish can ONLY move as prescribed by its environment! X Unblocked! Blocked!

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

  9. Depending on whether the new local environment is empty or not… Fish-Environment Interaction Make local environment in the direction the fish wants to move LocalEnvironment Class 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); } … either make a command that actually moves the fish… … and execute the unblocked command … or execute the blocked command No if-statements!

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

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

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

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

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

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

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

  17. User-Environment Interaction Make local environment for the location of the mouse click Depending on whether the new local environment is empty or not… AGlobalEnv Class 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); } … either add a fish there using the factory … or edit the fish’s local environment

More Related