1. class Discount {
    2. isPercentage: boolean
    3. amount: number
    4. constructor(
    5. isPercentage: boolean,
    6. amount: number) {
    7. this.isPercentage = isPercentage
    8. this.amount = amount
    9. }
    10. apply(article: Article) {
    11. if (this.isPercentage) {
    12. article.price = article.price - (article.price * this.amount)
    13. } else {
    14. article.price = article.price - this.amount
    15. }
    16. }
    17. }
    18. const discount: Discount = new Discount(false, 10)
    19. discount.apply({
    20. price: 39,
    21. vat: 0.2,
    22. title: 'Form Design Patterns'
    23. })