Last active
October 25, 2022 02:59
-
-
Save axel-andrade/1b97f5ba7f232edb1690981828bdd205 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Order = { | |
id: number; | |
value: number; | |
customer: string; | |
}; | |
class Payment { | |
private order: Order; | |
constructor(order: Order) { | |
this.order = order; | |
} | |
public getOrder(): Order { | |
return this.order; | |
} | |
public getFinalValue(): number { | |
const finalValue = this.order.value; | |
return finalValue; | |
} | |
} | |
class CreditPayment extends Payment { | |
private feeValue: number; | |
constructor(order: Order) { | |
super(order); | |
this.feeValue = 5; | |
} | |
public getFinalValue(): number { | |
const order = this.getOrder(); | |
const finalValue = order.value + this.getFee(order.value); | |
return finalValue; | |
} | |
private getFee(value: number): number { | |
return (value * this.feeValue) / 100; | |
} | |
} | |
class PixPayment extends Payment { | |
private discountValue: number; | |
constructor(order: Order) { | |
super(order); | |
this.discountValue = 10; | |
} | |
public getFinalValue(): number { | |
const order = this.getOrder(); | |
const finalValue = order.value - this.getDiscount(order.value); | |
return finalValue; | |
} | |
private getDiscount(value: number): number { | |
return (value * this.discountValue) / 100; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment