Algorithms and OOD (CSC 207 2014F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [Learning Outcomes] [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Readings]
Reference: [Student-Curated Resources] [Java 8 API] [Java 8 Tutorials] [Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2014S (Rebelsky)] [CSC 207 2014F (Walker)] [CSC 207 2011S (Weinman)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Planned Topics
TextBlock exampleAdditional Topics
if (num == 0 || num == 1 || num == 2 || num == 3 || num == 4
|| num == 5 || num == 6 || num == 7) {
if ((num >= 0) && (num < NUM_REGISTERS))
String comparison in C
char *s1;
char *s2;
...
if (s1 == s2)
{
...
} // same location
if (strcmp(s1,s2) == 0)
{
...
} // same string
String comparison in Java
String s1;
String s2;
...
if (s1 == s2)
{
...
} // same location
if (s1.equals(s2))
{
...
} // same string
Basic idea: You have an object. You know that it provides a certain set of capabilities. (In Java: either it implements an interface or it extends a class). You can use that object anywhere that you need something with those capabilities.
Concrete version 1: If A extends B, then
Concrete version 2: If O implements I, then
Yes, super/sub feels backwards from math, but it matches when you think about the set as being "things that can do all of this" rather than "the set of capabilities"
Example: How to get to McNallys
getToMcNallysFromScience3821(Walker w)
{
w.walkTo("door marked exit");
w.open("door marked exit");
w.lookFor(theLegendaryCSTeleportationChamber);
w.enter(theLegendaryCSTeleportationChamber);
w.type("McNallys", theLegendaryCSTeleportationChamber.getKeyboard());
w.click(theLegendaryCSTeleporationChamber.teleportButton());
w.pray();
}
public interface Walker
{
public void walkTo(String) throws Exception;
public void open(String);
public void lookFor(String);
public void enter(EnterableObject obj);
public void type(String, Keyboard);
public void click(button);
}
public class Student implements Walker
{
public void walkTo(String)
throws Exception
{
location = identifyWhereToFind(String);
orientSelfTo(location);
...
}
} //
public class StudentInWheelchair extends Student
{
@Override
public void walkTo(String)
throws Exception
{
this.wheelchair.orientTo(...);
arms.pushOnWheels();
...
}
} //
TextBlock ExampleWe did not get to this topic.