|Program 5: Inheritance and Interfaces||
FUTURE: Get rid of Save Authors button!
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.
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.
Step 2: Provide an abstract interface called IFormattableReference that includes the following:
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:
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:
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:
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.
In the screens below the buttons perform the following functions:
Tooltips are a useful feature to enhance user friendliness.
To add an abstract interface to a project in C#.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 embed the escape sequence \" in the output string.
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.