Design Patterns for Marine Biology Simulation - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Design Patterns for Marine Biology Simulation

Description:

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. ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 18
Provided by: steph172
Category:

less

Transcript and Presenter's Notes

Title: Design Patterns for Marine Biology Simulation


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
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
11
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
12
The Culmination of a Unified OO Pedagogy
end of 2nd semester.
MBS
Unit Tests
Design Patterns
Polymorphism
Abstract Structure and Behavior
13
Studying the Case Study
White-box Framework Extension by Subclassing
Unit Tests are the Specs!
Variant Fish Behavior
Variant Environment Behavior
14
Inheritance vs. Composition
Static Behavior!
Separate the variants from the invariants
Strategy Pattern
Dynamic Behavior Change
15
Comparative study vs. APMBS
Abstracted, decoupled design
Enhanced capabilities
  • Replaceable environments
  • Robustness
  • Security

16
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
17
For more information
  • http//www.exciton.cs.rice.edu/research/SIGCSE04/
  • E-mail
  • dxnguyen_at_rice.edu
  • mgricken_at_rice.edu
  • swong_at_rice.edu
Write a Comment
User Comments (0)
About PowerShow.com