- The Takeaway
- Document Management
- The Base Class: AnyOldDocument
- Economy in Coding
- The First Document Type: A Memo
- The Second Document Typean Invoice
- The Third and Last Document Typea Contract
- Leveraging Base Class Generality
- Polymorphism
- Complete Program Output
- Make Your Destructors Virtual
- Conclusion
- Additional Reading
The Third and Last Document Type—a Contract
I want to introduce one more document type—this time a contract illustrated in Listing 6.
Listing 6 Contract Document
class ContractDocument : AnyOldDocument { public: explicit ContractDocument(int Id, char* name, int docType, int number); virtual ~ContractDocument(); const int getPenaltyClauseValue(); void setPenaltyClauseValue(int number); }; ContractDocument::ContractDocument(int Id, char* name, int docType, int number) : AnyOldDocument(Id, name, docType, number) { printf ("Creating a contract document for: %s\n", name); } ContractDocument::~ContractDocument() { } const int ContractDocument::getPenaltyClauseValue() { return GetAssociatedNumber(); } void ContractDocument::setPenaltyClauseValue(int number) { SetAssociatedNumber(number); }
Listing 6 is pretty similar to the InvoiceDocument class. The main difference between these two classes is in semantics relating to our old friend: the base class data member called associatedNumber. In the case of InvoiceDocument, this data element represents a price, whereas in the case of the contract class, the associatedNumber element represents a penalty clause value. Penalty clauses are sometimes attached to contracts to act as an incentive for a contractor to complete the work.