Algorithms and OOD (CSC 207 2013F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
Admin
getX()getY()getAngle()getDistance()Interfaces provide the WHAT, not the how
public interface Point2D {
double getX();
double getY();
double getAngle();
double getDistance();
Point2D add(Point2D other);
// DOT PRODUCT!
Point2D multiply(Point2D other);
} // interface Point2D
public class XYPoint implements Point2D {
...
}
public class Vector2D implements Point2D {
...
}
Two magic things happen with the "implements" keywords
Consider squaring numbers
Scheme
(define square (lambda (num) (* num num)))a
C
int squareInt(int x) { return xx; } double squareDouble(double x) { return xx; }
Java permits overloading
int square(int x) { return xx; } double square(double x) { return xx; }
BUt the code is repetitious!
Scheme's approach is great, but not
public interface TextBlock {
int getWidth();
int getHeight();
String getRow(int i) throws Exception;
} // interface TextBlock
public class TextLine implements TextBlock {
...
}
public class VerticallyComposeTextBlock implements TextBlock {
...
}
TextBlock fiona = new TextLine("Hello");
TextBlock john = new TextLine("Goodbye");
TextBlock adam = new VCTB(fiona,john);
TextBlock mark = new TextLine("Mark");
TextBlock sunshine = new VCTB(adam, mark);
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Copyright (c) 2013 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by/3.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.