Design%20Patterns%20for%20Marine%20Biology%20Simulation - PowerPoint PPT Presentation

About This Presentation
Title:

Design%20Patterns%20for%20Marine%20Biology%20Simulation

Description:

Design Patterns for Marine Biology Simulation Dung Zung Nguyen Mathias Ricken Stephen Wong Rice University AP Marine Biology Simulation Where am I? – PowerPoint PPT presentation

Number of Views:145
Avg rating:3.0/5.0
Slides: 18
Provided by: Stephe678
Category:

less

Transcript and Presenter's Notes

Title: Design%20Patterns%20for%20Marine%20Biology%20Simulation


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

2
AP Marine Biology Simulation
a few pitfalls...
Key issue
Tight Coupling
3
Where am I?
On some global coordinate grid?
Think Simple.
I know where I am right here.
Which is not the same as here.
And not the same as here either.
Do I know my own coordinates? Does anyone else
know my coordinates? Should I know anyone elses
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
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
A Fishs Dilemma
Can I move forward?
Blocked case command
Unblocked case command
Send commands to local environment
The appropriate command is selected
The fish responds accordingly!
Send a message to the local environment!
?
Unblocked!
Blocked!
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!
?
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
Fish-Environment Interaction
Depending on whether the new local environment is
empty or not
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
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
end of 2nd semester.
MBS
Unit Tests
Design Patterns
Polymorphism
Abstract Structure and Behavior
12
Studying the Case Study
White-box Framework Extension by Subclassing
Unit Tests are the Specs!
Variant Fish Behavior
Variant Environment Behavior
13
Inheritance vs. Composition
Static Behavior!
Separate the variants from the invariants
Strategy Pattern
Dynamic Behavior Change
14
Comparative study vs. APMBS
Abstracted, decoupled design
Enhanced capabilities
  • Replaceable environments
  • Robustness
  • Security


15
Is it really about Fish?
Its all about Abstraction!
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_at_rice.edu
  • mgricken_at_rice.edu
  • swong_at_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 fishs local environment
Write a Comment
User Comments (0)
About PowerShow.com