23
Marine Biology Marine Biology Simulation Simulation Part I: Introduction Part I: Introduction Dung “Zung” Nguyen Dung “Zung” Nguyen Mathias Ricken Mathias Ricken Stephen Wong Stephen Wong TeachJava 2004! TeachJava 2004! June 25, 2004 June 25, 2004

Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

Embed Size (px)

Citation preview

Page 1: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

Marine Biology SimulationMarine Biology SimulationPart I: IntroductionPart I: Introduction

Dung “Zung” NguyenDung “Zung” NguyenMathias RickenMathias RickenStephen WongStephen Wong

TeachJava 2004!TeachJava 2004!

June 25, 2004June 25, 2004

Page 2: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

The Role of ProgrammingThe Role of Programming

Important skillImportant skillShould be taught early in a student’s careerShould be taught early in a student’s career

Usually taught Usually taught imperative-firstimperative-firstConcentrates on language elements like Concentrates on language elements like expressions, operators, functions, pointers…expressions, operators, functions, pointers…

Page 3: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

Problems Teaching Imperative-FirstProblems Teaching Imperative-First

Focus on syntactical elements Focus on syntactical elements

Exercises too simple to be motivatingExercises too simple to be motivating

Too little emphasis on designToo little emphasis on design

Biased against students without prior Biased against students without prior knowledgeknowledge

Page 4: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

Object-OrientationObject-Orientation

Beneficial to software qualityBeneficial to software qualityCorrect, robust, flexible, and extensibleCorrect, robust, flexible, and extensible

Extensively covers software designExtensively covers software design

Examples are more challenging and Examples are more challenging and motivatingmotivating

Usually considered “advanced concept”Usually considered “advanced concept”

Page 5: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

AssignmentsAssignments

Assignments have to be complexAssignments have to be complexHighlight benefits of object-orientationHighlight benefits of object-orientation

Large design portionLarge design portionFind proper abstractions, variants / invariantsFind proper abstractions, variants / invariantsSolve family of problemsSolve family of problems

Challenge to find suitable assignmentsChallenge to find suitable assignmentsExample: Marine Biology SimulationExample: Marine Biology Simulation

Page 6: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

AP Marine Biology SimulationAP Marine Biology Simulation

Case studies in AP curriculum since 1994Case studies in AP curriculum since 1994

Argument:Argument:““Some good reasons to use a case study in AP Some good reasons to use a case study in AP

Computer Science include:Computer Science include:• Working with a program of significant lengthWorking with a program of significant length• Thinking through issues of good program Thinking through issues of good program

designdesign• Learning from an expert programmer”Learning from an expert programmer”

(AP Marine Biology Simulation Case Study – Teacher’s Manual)(AP Marine Biology Simulation Case Study – Teacher’s Manual)

Page 7: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

AP Marine Biology SimulationAP Marine Biology Simulation

Goal:Goal:““Through the Through the AP Marine Biology Simulation Case AP Marine Biology Simulation Case

StudyStudy, the strategies, vocabulary, and , the strategies, vocabulary, and techniques of object-oriented design will be techniques of object-oriented design will be emphasized.”emphasized.”

(AP Marine Biology Simulation Case Study – Teacher’s Manual)(AP Marine Biology Simulation Case Study – Teacher’s Manual)

ShortcomingsShortcomingsImproper abstractions, incorrect delineation of Improper abstractions, incorrect delineation of responsibilitiesresponsibilitiesTight couplingTight coupling

not robustnot robust not flexible and extensiblenot flexible and extensible

Page 8: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

AP Marine Biology SimulationAP Marine Biology Simulation

DemoDemo

Page 9: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

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 CouplingTight Coupling

Page 10: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

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 11: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

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 12: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

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 13: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

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 14: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

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

MoveCommand

Unblocked!

Blocked!X

A fish can ONLY move as

prescribed by its environment!

Page 15: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

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!

Page 16: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

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 17: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

Fish-Environment InteractionFish-Environment Interaction

Code is used in a class assignmentand has been removed

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 18: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

Design BenefitsDesign Benefits

Replaceable Replaceable environmentsenvironments

Different fishDifferent fish

RobustnessRobustness

Decoupled, abstract designDecoupled, abstract design

Enhanced capabilitiesEnhanced capabilities

Page 19: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

Rice Marine Biology SimulationRice Marine Biology Simulation

DemoDemo

Page 20: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

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 21: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

Problems Using This in AP ClassesProblems Using This in AP Classes

Defined curriculumDefined curriculum

Students must perform well in examsStudents must perform well in examsTeach what exams requireTeach what exams require

Current curriculum disagrees with our Current curriculum disagrees with our approachapproach

Rice MBS is for university-level classesRice MBS is for university-level classes

Page 22: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

ResultsResults

Addresses problems Addresses problems of imperative-firstof imperative-first

Focus on designFocus on design

Motivating Motivating assignmentsassignments

Not biased againstNot biased againstLack of experienceLack of experienceGenderGenderDeclared MajorDeclared MajorYear in SchoolYear in SchoolSAT ScoresSAT Scores

Objects-first is programming for everyoneObjects-first is programming for everyone

AP curriculum will hopefully changeAP curriculum will hopefully change

Page 23: Marine Biology Simulation Part I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004

Future WorkFuture Work

Make simulation guarantee progressMake simulation guarantee progressPrevent one fish from blocking othersPrevent one fish from blocking others

Extra credit competition using MBSExtra credit competition using MBSGame of life, outbreed other species?Game of life, outbreed other species?

Study MBS along several cognitive Study MBS along several cognitive dimensionsdimensions

Improve assignment qualityImprove assignment quality