170 likes | 292 Views
OOP in Introductory CS. Better students though abstraction. Stephen Wong and “Zung” Nguyen Rice University. A Struggling Pedagogy. Java Power Tools Northeastern Univ. Karel the Robot Univ. Waterloo and others. Graphics-based OO Wiliams College. OO Lab Project Univ. Wisconsin.
E N D
OOP in Introductory CS Better students though abstraction Stephen Wong and “Zung” Nguyen Rice University
A Struggling Pedagogy Java Power Tools Northeastern Univ. Karel the Robot Univ. Waterloo and others Graphics-based OO Wiliams College OO Lab Project Univ. Wisconsin OO Overkill Duke Univ. Polymorphic Panelists OOPSLA OO Workshop Etc., etc.
Old Intro CS at Oberlin • CS 1 & 2 in Java • Was procedural + a bit of OOP • 3rd semester in Scheme • Problems • Students knew syntax but not programming. • A big conceptual jump into Scheme • No experience with design. • No large scale project experience. • Non-inspiring course.
What can students do? Koch Curves Client-server game Multiple controllable threads Remote, distributed agents Frogger, pretty Frogger, extended Ballworld Animation Frogger, nuts Puzzle Game Movie loop, cute Swarming/Flocking Simulation Movie loop, techno
Definitely! OO First? Students intrinsically understand polymorphism Myth: OO is an advanced concept. Students intrinsically understand how objects interact Students intrinsically understand object behaviors. Leverage what the students already understand!
Learning abstract thinking is not easy. Abstraction the key to understanding CS Abstract objects Abstract behaviors It’s not that easy… Concrete objects Concrete behaviors Intro CS must focus on learning Abstraction!
What is a Design Pattern? • An abstracted solution to a class of problems. • Describes relationships between objects • Describes when and how those relationships can used. But why do they work? Design patterns are expressions of fundamental CS principles
Polymorphism Abstract Objects & Behaviors Delegation Strategies Composition Encapsulation Factories State Pattern Visitors Abstract Construction Adapters Decorators Anonymous classes Recursion Lambda Calculus Decoupling The Road Concrete Objects
AVisitor +methodA(AElement e) +methodB(AElement e) Visitor1 +methodA(AElement e) +methodB(AElement e) Visitor2 +methodA(AElement e) +methodB(AElement e) AElement +accept(AVisitor v) +other methods… ElementA +accept(AVisitor v) ElementB +accept(AVisitor v) Example: Visitor Pattern Abstractly Equivalent Variant, Decoupled Algorithms Concrete Visitors One method per element Abstractly Equivalent Abstract, Invariant Data Structure v.methodA(this); v.methodB(this); Concrete Elements
Visitors Teach… • Decoupling of variant and invariant • Polymorphic dispatching • Encapsulation of a process • Abstract equivalence • If elements are empty vs. non-empty lists • Visitor methods: base and inductive cases. • Declarative style programming Design Patterns are tools to teach CS concepts
Strategy Adapter Decorator State Visitor Factory Composite MVC Design Patterns as Embodiments of Abstract Concepts Abstract behavior Encapsulation Delegation Variant vs. Invariant Abstract construction Decoupled behavior Recursion
TangibleAbstraction Languageof Abstraction Focus on Abstraction The Role of Design Patterns Design Patterns
AKochState grow(AFactory f) paint() 1 * DrawManyState grow(AFactory f) paint() DrawOneState grow(AFactory f) paint() 1 LRStruct execute(IAlgo algo) uses 1 1 GrowAlgo nullCase() nonNullCase() PaintAlgo nullCase() nonNullCase() AFactory +makeOne() +makeMany() LRStruct Visitor Pattern Algorithms Concrete States SnowflakeFactory +makeOne() +makeMany() CurveFactory +makeOne() +makeMany() Example: Koch Curve Lab A curve between 2 points State Design Pattern Koch -Point a,b +grow(AFactory f) +paint() Only one line of code that actually grows/paints! Base case construction Base case Base case Inductive case Inductive case Composite Pattern Factory Design Pattern Inductive case construction Concrete Factories Run program
Focus on the objects/classes, not the implementation Focus on design, not syntax Focus on the problem, not API Technology an Integral Part of the Pedagogy UML Diagramming Tool Integrated DevelopmentEnvironment Focus on the Abstraction!!
Plugging into the Students What is it that really interests our students? Robotics AI Games Networking Graphics “Real Programs”
Getting the Students to Plug In Graphical Interfaces Cutting edge technology Fun, fun, fun!!! Simplicity + Power Unimagined capabilities
Synergy Fundamental CS Principles Learning Abstract Thinking. The best students ever. Leveraged Student Experiences Design Patterns Focus on Abstraction Cohesive Pedagogical Path Development Tools Rich Lab Experiences Fun, inspiring results http://www.exciton.cs.rice.edu/cs150 http://www.exciton.cs.rice.edu/cs151 Demos