Algorithms and OOD (CSC 207 2013F) : EBoards

CSC207.01 2013F, Class 12: Interfaces and Polymorphism





An example: Text blocks

    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);

Copyright (c) 2013 Samuel A. Rebelsky.

Creative Commons License

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