230 likes | 355 Views
Marine Biology Simulation Part I: Introduction. Dung “Zung” Nguyen Mathias Ricken Stephen Wong. TeachJava 2004! June 25, 2004. The Role of Programming. Important skill Should be taught early in a student’s career Usually taught imperative-first
E N D
Marine Biology SimulationPart I: Introduction Dung “Zung” Nguyen Mathias Ricken Stephen Wong TeachJava 2004! June 25, 2004
The Role of Programming • Important skill • Should be taught early in a student’s career • Usually taught imperative-first • Concentrates on language elements like expressions, operators, functions, pointers…
Problems Teaching Imperative-First • Focus on syntactical elements • Exercises too simple to be motivating • Too little emphasis on design • Biased against students without prior knowledge
Object-Orientation • Beneficial to software quality • Correct, robust, flexible, and extensible • Extensively covers software design • Examples are more challenging and motivating • Usually considered “advanced concept”
Assignments • Assignments have to be complex • Highlight benefits of object-orientation • Large design portion • Find proper abstractions, variants / invariants • Solve family of problems • Challenge to find suitable assignments • Example: Marine Biology Simulation
AP Marine Biology Simulation • Case studies in AP curriculum since 1994 • Argument: “Some good reasons to use a case study in AP Computer Science include: • Working with a program of significant length • Thinking through issues of good program design • Learning from an expert programmer” (AP Marine Biology Simulation Case Study – Teacher’s Manual)
AP Marine Biology Simulation • Goal: “Through the AP Marine Biology Simulation Case Study, the strategies, vocabulary, and techniques of object-oriented design will be emphasized.” (AP Marine Biology Simulation Case Study – Teacher’s Manual) • Shortcomings • Improper abstractions, incorrect delineation of responsibilities • Tight coupling not robust not flexible and extensible
Unenforceable contracts Replicated data Insecure architecture Limited extensibility AP Marine Biology Simulation a few pitfalls... Key issue: Tight Coupling
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
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.
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!
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
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 can ONLY move as prescribed by its environment! X Unblocked! Blocked!
A fish does not need to know its x-y coordinate! A fish does not need to know “how” to move! Decoupled, yet interactive behavior! A fish is decoupled from the global environment!
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
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 Code is used in a class assignment and has been removed … either make a command that actually moves the fish… … and execute the unblocked command … or execute the blocked command No if-statements!
Design Benefits Decoupled, abstract design Enhanced capabilities • Replaceable environments • Different fish • Robustness
The Culmination of a Unified OO Pedagogy ~ end of 2nd semester. MBS Unit Tests Design Patterns Polymorphism Abstract Structure and Behavior
Problems Using This in AP Classes • Defined curriculum • Students must perform well in exams • Teach what exams require • Current curriculum disagrees with our approach • Rice MBS is for university-level classes
Results • Addresses problems of imperative-first • Focus on design • Motivating assignments Objects-first is programming for everyone • Not biased against • Lack of experience • Gender • Declared Major • Year in School • SAT Scores AP curriculum will hopefully change
Future Work • Make simulation guarantee progress • Prevent one fish from blocking others • Extra credit competition using MBS • Game of life, outbreed other species? • Study MBS along several cognitive dimensions • Improve assignment quality