Polymorphism (poly = many, morphe = form) is the ability to treat many different forms of an object as if they were the same.
Each form needs printing at some time. In procedural programming, we would either code a print function to handle the three different forms or we would write three different functions (printExpenseForm, printLoanForm, printPurchaseForm).
class Form {
public:
virtual void print();
};
class ExpenseForm : public Form {
public:
virtual void print();
};
class LoanForm : public Form {
public:
virtual void print();
};
class PurchaseForm : public Form {
public:
virtual void print();
};
Form* pForm[10]
//create Expense/Loan/Purchase Forms…
for (short i=0 ; i < 9 ; i++)
pForm->print();
Here we create ten objects that might be any combination of Expense, Loan, and Purchase Forms. However, because we are dealing with pointers to the base class, Form, we do not need to know which sort of form object we have; the correct print method is called automatically.
virtual void clear();
virtual const IccBuf& get();
virtual void put(const IccBuf& buffer);
These methods have been implemented in the subclasses of IccResource wherever possible:
Class | clear | get | put |
---|---|---|---|
IccConsole | × | × | ✓ |
IccDataQueue | ✓ | ✓ | ✓ |
IccJournal | × | × | ✓ |
IccSession | × | ✓ | ✓ |
IccTempStore | ✓ | ✓ | ✓ |
IccTerminal | ✓ | ✓ | ✓ |
These virtual methods are not supported by any subclasses of IccResource except those in the table above.