Objectives

The objectives of this lab are to:

  • Understand the ideas behind abstraction
  • Sucessfully implement abstraction in the Network system.

Network-V5

In this step, you will create version 5 of the Network system (our menu driven messaging system). In this version, you will use abstraction in the inheritance hierarchy.

Abstraction in Network-V5

  • Make the Post class abstract and add an abstract method called displayExcerpt() to it. The return type of this method should be a String.

  • In Post's subclasses, provide the concrete implementation for this method.

  • Message Post code:

    public String displayExtract()
    {
        return "Message extract "+ message.substring(0,10) + "....";
    }
  • PhotoPost code:
    public String displayExtract()
    {
        return "Photo caption: " + caption.substring(0,10) + "....";
    }
  • Save your code.

  • Note that this code does not "do" anything as we have not called the displayExtract method from anywhere. This is just a very short lab to illustrate the abstract class and method concept.

Solution: Network-V5