November 2018
Beginner
502 pages
10h 22m
English
We can use classes and interfaces together by defining the contract in an interface and then implementing the class as per the interface. We specify that a class is implementing a particular interface using the implements keyword.
As an example, we can define an interface for the order detail and then a class that implements this interface:
interface IOrderDetail { product: Product; quantity: number; getTotal(discount: number): number;}class OrderDetail implements IOrderDetail { product: Product; quantity: number; getTotal(discount: number): number { const priceWithoutDiscount = this.product.unitPrice * this.quantity; const discountAmount = priceWithoutDiscount * discount; return priceWithoutDiscount - discountAmount; ...Read now
Unlock full access