Home > Articles > Programming > C/C++

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

The Base Class: AnyOldDocument

Listing 2 illustrates the base document class from which I will derive all my required document subclasses.

Listing 2 Document Base Class

class AnyOldDocument {
public:
  AnyOldDocument();
  AnyOldDocument(int Id, char* name, int docType);
  AnyOldDocument(int Id, char* name, int docType, int theNumber);
  virtual ~AnyOldDocument();

  const int GetAssociatedNumber() { return associatedNumber; };
  void SetAssociatedNumber(int newNumber) { associatedNumber = newNumber; };
  virtual void StoreDocument() {};
  virtual void GetDocument() {};
  virtual void DeleteDocument() {};

private:
  int documentId;
  char * documentName;
  int documentType;
  int associatedNumber;
};

enum documentType { INVOICE = 1, CONTRACT = 2,
          MEMO = 3, PAYSLIP = 4,
          TAXFORM = 5, SOCIALSEC = 6,
          ACCOUNTING = 7 };

The AnyOldDocument class contains three constructors—one with no parameters, one with two parameters, and one with three parameters. These constructors are used to create the derived documents. It has four data members that are used for differentiating the various documents of interest. Notice also the virtual destructor.

The GetAssociatedNumber()and SetAssociatedNumber() member functions manipulate an application entity discussed below. The last three member functions in AnyOldDocument relate to the operations that can be carried out on the document entity; for example, storing it in an archive, retrieving it from an archive, and permanently deleting it from an archive. The latter three operations are similar to those that can be used in source code control systems.

  • + Share This
  • 🔖 Save To Your Account