
export interface HasFormatter {
name?: string;
age?: number;
format(): string;
}
import { HasFormatter } from "../interfaces/hasformatter";
class Invoice2 implements HasFormatter {
constructor(
private client: string,
public details: string,
readonly amount: number
) { }
public format() {
this.client = this.client + '修改'
return `${this.client} owes ¥${this.amount} for ${this.details}`;
}
}
export { Invoice2 };
import { HasFormatter } from "../interfaces/hasformatter";
export class Payment implements HasFormatter {
constructor(
readonly recipient: string,
private details: string,
public amount: number
) { }
format() {
return `${this.recipient} owes ¥${this.amount} for ${this.details}`;
}
}
import { Invoice2 } from "./classes/invoice2";
import { Payment } from "./classes/payment";
import { HasFormatter } from "./interfaces/hasformatter";
let docOne: HasFormatter;
let docTwo: HasFormatter;
docOne = new Invoice2("mario", "web work", 250);
docTwo = new Payment("luigi", "plumbing work", 300);
console.log(docOne.format());
console.log(docTwo.format());
export {};