CookbookAttrs represents cookbook-specific attributes while reusing common title and author fields from Attributes. It adds a Region value for cookbook classification. section 2.3.3
Its design responsibilities include:
- Accepting title, author surname, author given name, and region through its constructor. section 2.3.3
- Using the inherited Attributes matching behavior before checking cookbook-specific data. section 2.3.3
- Representing regions as CHINA, FRANCE, INDIA, ITALY, MEXICO, US, or UNSPECIFIED. section 2.3.3
- Supporting polymorphic storage in Book and cookbook insertion and lookup through Catalogue. section 2.3.3
A cookbook entry
catalogue.add(new CookbookAttrs("The Woks of Life", "Leung", "Bill", Region::CHINA)); section 2.3.3
Listing 2.9 (Program 2.3 Books-3): Fiction.h
#include "Book.h"
#include "FictionAttrs.h"
using namespace std;
class Fiction : public Book #1
{
public:
Fiction(FictionAttrs * const attrs) : Book(attrs) {} #2
};
#1 Class Fiction is a subclass of class Book.
#2 Call the constructor of superclass Book.
The related class listing shows the parallel Cookbook subclass that passes CookbookAttrs to its Book superclass. section 2.3.3
