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
import {Customer} from './customer'; | |
import {Order} from './order'; | |
export class OrderDiscounter { | |
constructor(public customer: Customer, public order: Order) {} | |
discountedAmount() { | |
return (100 - this.customer.discount()) * this.order.amount; | |
} | |
} |
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
export class Order { | |
constructor(public amount: number) {} | |
} |
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
import {Order} from './order'; | |
export class Customer { | |
constructor(public orders: Order[]) {} | |
discount() { | |
if (this.orders.length > 5) { | |
return 10; | |
} else { |
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
import {DiscountCalculator, Order} from './order'; | |
export class Customer implements DiscountCalculator { | |
constructor(private orders: Order[]) {} | |
discount() { | |
if (this.orders.length > 5) { | |
return 10; | |
} else { |
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
export class Order { | |
constructor(private discount: DiscountCalculator, private amount: number) {} | |
discountedAmount() { | |
return (100 - this.discount.discount()) * this.amount; | |
} | |
} | |
export interface DiscountCalculator { |
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
import {Customer} from './customer'; | |
export class Order { | |
constructor(private customer: Customer, private amount: number) {} | |
discountedAmount() { | |
return (100 - this.customer.discount()) * this.amount; | |
} | |
} |
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
import {Order} from './order'; | |
export class Customer { | |
constructor(private orders: Order[]) {} | |
discount() { | |
if (this.orders.length > 5) { | |
return 10; | |
} else { |
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
const customerOrders = findOrdersBy(customerId); // instead of findOrdersByCustomer(customerId) | |
const userOrders = findOrdersBy(creatorId); // instead of findOrdersByCreator(creatorId) |
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
function findOrdersBy(customerId: CustomerId): Order[]; | |
function findOrdersBy(creatorId: UserId): Order[]; | |
function findOrdersBy(id): Order[] { | |
... | |
} |
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
export function findOrdersBy(customerId: string): Order[] { | |
... | |
} |