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)]
Topics to discuss
Broad: Objects in one class include objects from another class and conceal those inner objects.
dumpadd, getWrapper-like patterns
Example: Wrapping/adapting java.util.Queue to meet the taojava.util.Linear
interface.
public class LinearQueue<T>
implements LinearStructure<T>
{
// +--------+------------------------------------------------------
// | Fields |
// +--------+
java.util.Queue<T> core = new java.util.Queue<T>();
// +---------+-----------------------------------------------------
// | Methods |
// +---------+
public void put(T val)
throws Exception
{
core.add(val);
} // put(T)
public T get()
throws Exception
{
core.remove();
} // remove()
public T peek()
throws Exception
{
core.element();
} // peek()
public boolean isEmpty()
{
return (core.peek() != null);
} // isEmpty()
public boolean isFull()
{
return false;
} // isFull()
public Iterator<T> iterator()
{
return core.iterator();
} // iterator()
} // LinearQueue
What's the difference between Comparator and Comparable?
Comparatorobjects provide the methodcomparewhich takes two parameters and returns an integer that describes their ordering.
Comparableobjects provide the methodcompareTowhich takes one parameter and returns an integer that desribes the ordering of the object and its parameter.Most of the standard objects implement
Comparable<SameType>.