Program 5: Inheritance and Interfaces

Objectives: Gain experience using inheritance and interfaces.  

Description: This program is intended to provide you with experience designing derived classes and interfaces.

Previous deliverables have provided a beginning for the reference formatter program, but there is much work to be done.  You recently created a clsReference program that was envisioned as serving as a base class for more specific derived classes.  As it stands, clsReference is too generic to define real objects; we need to be more specific before we can think of instantiating actual references like books and journals.  Part I of this program requires you to implement abstract classes and abstract interfaces. 

Part I

Recall that abstract classes are classes that are defined but for which the programmer never intends to instantiate any objects. These normally serve as superclasses in inheritance situations, and are referred to as abstract superclasses. The sole purpose of an abstract class is to provide an appropriate template superclass from which other classes may inherit interface and/or implementation.  Abstract classes are used to facilitate reuse because they specify code common to all its derived classes.

An abstract interface is a specification of a set of methods that are to be implemented in the class that inherits from it.  An abstract interface resembles an abstract class, but contains only abstract methods. An abstract class can contain abstract methods as well as constants, variables and concrete methods, while the interface contains only method signatures. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile.

Step 1:  Modify clsReference so that it can serve as an abstract class.

  • Insert the keyword MustInherit

  • Include the keywords Protected and MustOverride with the methods if they are necessary.


Step 2: Provide an abstract interface called IFormattableReference that includes the following:

Method signatures:

  • formatMLA

  • formatAPA

  • formatChicago

Modify clsReference to implement IFormattableReference.  The derived classes will implement the interface.

Part II

Part II of this program requires you to practice using inheritance by deriving classes from the abstract class clsReference and implementing the interface defined in Part I.

You will be implementing the inheritance structure shown in the class diagram below:

Part II  Step 1: Create a new class called clsBook that is derived from clsReference. It should add new class members including the following instance variables:

  • publisher

  • city

  • state

  • country

and the following methods:


Part II Step 2: Create a new class called clsChapter that inherits from clsBook.  It should also add class members indicated in the figure below, including the following instance variables:

  • editor (arrayList of names)

  • bookTitle

  • beginningPage

  • endingPage

and the following methods


Part II Step 3: Create a new class called clsJournal that inherits from clsReference.  It should also add class members indicated in the figure below, including the following instance variables:

  • source

  • volume

  • number

  • beginningPage

  • endingPage

and the following methods


As always, the classes, instance variables and methods listed below may not be exhaustive, and should be adapted as needed as you formulate your solution.  Note that initial designs evolve as system details become more evident.  However, you should contact the professor if you discover the need for any serious deviations from this general design.

Interface Design

In the screens below the buttons perform the following functions:

Button Purpose
Add Author Adds a single author to the ArrayList-of-authors instance variable in the reference object, increments the author counter, updates the author counter label, and clears the author fields.
Save Authors Depending on which radio button is clicked, moves to the correct input field.
Add Editor Adds a single editor to the ArrayList-of-editors instance variable, increments the editor counter, updates the editor counter label, and clears the editor fields.
Save Editors Depending on which radio button is clicked, move to the correct input field.
Submit Book Calls the routines to set the book title, publication date, publisher, city, state, and country.
Submit Chapter Calls the routines to set the chapter title, publication month, day, and year, publisher, city, state, and country where the publisher is based, book title, and beginning page and ending page.
Submit Journal Calls the routines to set the paper title, the journal month, day, and year of publication, journal title, the beginning page and ending page, the journal volume and number .

Click here for some sample screenshots. 

VB Specifics:

Tooltips are a useful feature to enhance user friendliness.

To add an abstract interface to a project in VB.NET you right click the project name in the Solution Explorer, then click Add, then New Item, and then select Interface from the Templates screen.

Note: To print a quotation mark in a string, one approach is to create a constant and then concatenate it to your output string.

Const QUOTE As Char = ChrW(34) or Const QUOTE As Char = """"

To add the tabs to your form simply add a TabControl from the toolbox and size it appropriately.

Note:  In this deliverable you are NOT required to save more than one reference entry at a time.  Saving them to an ArrayList is a feature of the next deliverable.