+ All Categories
Home > Documents > Design Patterns for Marine Biology Simulation

Design Patterns for Marine Biology Simulation

Date post: 07-Jan-2016
Category:
Upload: badrani
View: 32 times
Download: 0 times
Share this document with a friend
Description:
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. - PowerPoint PPT Presentation
17
Design Patterns for Design Patterns for Marine Biology Marine Biology Simulation Simulation Dung “Zung” Nguyen Dung “Zung” Nguyen Mathias Ricken Mathias Ricken Stephen Wong Stephen Wong Rice University Rice University
Transcript
Page 1: Design Patterns for  Marine Biology Simulation

Design Patterns for Design Patterns for Marine Biology SimulationMarine Biology Simulation

Dung “Zung” NguyenDung “Zung” NguyenMathias RickenMathias RickenStephen WongStephen WongRice UniversityRice University

Page 2: Design Patterns for  Marine Biology Simulation

AP Marine Biology SimulationAP Marine Biology Simulation

Unenforceable contracts

Insecure architecture

a few pitfalls...a few pitfalls...

Key issue:Key issue:

Limited extensibility

Replicated data

Tight Tight CouplingCoupling

Page 3: Design Patterns for  Marine Biology Simulation

Where am I?Where am I?

Latitude = 29.65 Longitude = 95.28

On some global coordinate grid?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.Think Simple.I know where I am: right I know where I am: right herehere..

X

X

Which is Which is notnot the same as the same as herehere..

X

And And notnot the same as the same as herehere either. either.

Page 4: Design Patterns for  Marine Biology Simulation

Each fish has its Each fish has its ownown local local environmentenvironment

XX

X

X

X

The local environment is an The local environment is an indirection layer between the fish indirection layer between the fish

and the global environment.and the global environment.

Page 5: Design Patterns for  Marine Biology Simulation

Fish and their EnvironmentFish and their EnvironmentA fish has a local

environmentThe 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.

Page 6: Design Patterns for  Marine Biology Simulation

A Fish’s DilemmaA Fish’s Dilemma

Unblocked!Blocked!

Can I move forward?Can I move forward?Send a message to the Send a message to the local environment!local environment!

Blocked case commandBlocked case commandUnblocked case commandUnblocked case commandSend commands to Send commands to local environmentlocal environment

The appropriate command is selectedThe appropriate command is selectedThe fish responds accordingly!The fish responds accordingly!

X

Page 7: Design Patterns for  Marine Biology Simulation

Or…Or…The appropriate command is selectedThe appropriate command is selectedLocal environment makes a Local environment makes a move commandmove command

Move command sent to fishMove command sent to fishIf desired, fish applies move command If desired, fish applies move command A fish does not need to know A fish does not need to know its x-y coordinate! its x-y coordinate!

A fish does not need to know A fish does not need to know “how” to move!“how” to move!

A fish is decoupled from the A fish is decoupled from the global environment!global environment!

MoveCommand

Unblocked!

Blocked!X

A fish can ONLY move as

prescribed by its environment!

Page 8: Design Patterns for  Marine Biology Simulation

Fish-Environment InteractionFish-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

Page 9: Design Patterns for  Marine Biology Simulation

Fish-Environment InteractionFish-Environment Interactionpublic 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

Page 10: Design Patterns for  Marine Biology Simulation

Design Patterns for DecouplingDesign Patterns for Decoupling

MVC Decouples a model

from its view

OBSERVER-OBSERVABLEDecouples sender and

multiple receivers

VISITOR Decouples structure and

its behaviors.

FACTORYDecouples framework from object creation

COMMANDDecouples decisions

from actions.

COMPOSITEDecouples a whole

from its parts.

INTEGRAL COMPONENTS OF A UNIFIED PEDAGOGY

Page 11: Design Patterns for  Marine Biology Simulation

The Culmination of a The Culmination of a Unified OO PedagogyUnified OO Pedagogy

Abstract Structure and BehaviorAbstract Structure and Behavior

PolymorphismPolymorphism

Design PatternsDesign Patterns

Unit TestsUnit Tests

MBSMBS ~ end of 2nd semester.

Page 12: Design Patterns for  Marine Biology Simulation

Studying the Case StudyStudying the Case Study

SimpleFishUnboundedEnv Variant Fish Behavior

Variant Environment Behavior

Re-implement as per given specs.

Re-implement as per given specs.

White-box Framework:Extension

by Subclassing

Page 13: Design Patterns for  Marine Biology Simulation

Inheritance vs. CompositionInheritance vs. Composition

Strategy Pattern

+ void move()

+ void move() + void move()

Static Behavior! Separate the variants from the invariants

Page 14: Design Patterns for  Marine Biology Simulation

Comparative study vs. APMBSComparative study vs. APMBS

Replaceable environmentsReplaceable environments RobustnessRobustness SecuritySecurity

Enhanced capabilitiesEnhanced capabilities

Abstracted, decoupled designAbstracted, decoupled design

Page 15: Design Patterns for  Marine Biology Simulation

Is it really about Fish?Is it really about Fish? !! !

Design patterns are expressions of recurring abstractionsthat 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!It’s all about Abstraction!

Why design patterns?

Page 16: Design Patterns for  Marine Biology Simulation

For more information:For more information:

http://www.exciton.cs.rice.edu/research/SIGCSE04/http://www.exciton.cs.rice.edu/research/SIGCSE04/ To download code files:To download code files:

– Username: Username: sigcse04sigcse04– Password: Password: ricembsricembs

E-mail:E-mail:– [email protected]@rice.edu– [email protected]@rice.edu– [email protected]@rice.edu

Page 17: Design Patterns for  Marine Biology Simulation

User-Environment InteractionUser-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 ClassMake 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


Recommended