Exercise: TypeScript Classes

Idea: Working with TypeScript classes, including interfaces, abstract classes, constructors, inheritance, method overloading ..
Background: Classes: http://www.typescriptlang.org/docs/handbook/classes.html Interfaces: https://www.typescriptlang.org/docs/handbook/interfaces.html

Implement the following Class-diagram in a new TypeScript project.

Add a constructor to class BankAccount to initialize 'ssn' (Social Security Number), 'firstName', 'lastName' and optional 'rateOfInterest'. The 'balance' should be initialized to 0, accountNumber to the nextAccountNumber (don't forget to increase the nextAccountNumber after use!).

Constructors in OverdraftAccount and LoanAccount must call super() - the constructor from BankAccount.

The function addInterest() is overloaded in the interface IBankAccount, but JavaScript do not allow function-overloading (since Type-less). How to solve? - one solution is to use optional parameters (marked with: '?') in the classes.

Don't forget the keyword 'abstract' to abstract classes and abstract functions.

In JavaScript we are using 'implements' and 'extends' (like we do in Java and not ':' as in c#) when implementing an interface or extends (inherit from) a class.


Enjoy ;-) / Henrik H