----
class Person { ... }; 
class BankAccount
{ 
public:
  BankAccount(const Person* primaryOwner, const Person* jointOwner);     
  virtual ~BankAccount();

virtual long balance() const = 0;
...
};
class SavingAccount: public BankAccount {
public:
  SavingsAccount(const Person* primaryOwner, const Person* jointOwner);       
  ~SavingsAccount();
  void creditInterest();
  ...
};
...
List<BankAccount*>allAccounts;    // All the accounts of the bank
...
// a loop that will compile, but that is nonetheless evil
for ( list<BankAccount*>::iterator p = allAccounts.begin();   
  p != allAccounts.end();
  ++p)
{ 
static_cast<SavingsAccount*>(*p)->creditInterest();
}
----

To avoid bugs generations (Maintainability & Reliability).

This code works as long as this loop is executed on lists containing only SavingAccounts. If one day, a new type of account is defined as derived from BankAccount and added to this list, the code does not work any more.


ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
