This file contains hidden or 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
// After changing the code, Invoice should look like: | |
export class Invoice { | |
private readonly shippingPricer: ShippingPricer; | |
// ... | |
constructor( | |
billingDate: OurDate, | |
openingDate: OurDate, | |
originator: Originator, |
This file contains hidden or 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 Invoice { | |
//... | |
public getValue(): Money { | |
const total = this.itemsSum(); | |
if (this.billingDate.after(OurDate.yearEnd(this.openingDate))) { | |
if ( | |
this.originator.getState() === "FL" || | |
this.originator.getState() === "NY" | |
) { |
This file contains hidden or 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 Element { | |
private readonly name: string; | |
private text: string; | |
constructor(name: string) { | |
this.name = name; | |
this.text = ""; | |
} | |
addText(newText: string): void { |
This file contains hidden or 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 InMemoryDirectory { | |
private readonly elements: Element[]; | |
constructor() { | |
this.elements = []; | |
} | |
public addElement(newElement: Element): void { | |
this.elements.push(newElement); | |
} |
This file contains hidden or 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 CppClass { | |
private readonly name: string; | |
private readonly declarations: Declaration[]; | |
constructor(name: string, declarations: Declaration[]) { | |
this.name = name; | |
this.declarations = declarations; | |
} | |
public getDeclarationCount(): number { |
This file contains hidden or 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 Reservation { | |
private duration: number; | |
private dailyRate: number; | |
private readonly date: Date; | |
private readonly customer: Customer; | |
private readonly fees: FeeRider[]; | |
constructor(customer: Customer, duration: number, dailyRate: number, date: Date) { | |
this.fees = []; | |
this.customer = customer; |
This file contains hidden or 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
// Step 4 | |
export class GDIBrush implements PointRenderer { | |
colorId: number; | |
public draw(renderingRoots: Point[], colors: ColorMatrix, selection: Point[]): void { | |
const renderer = new Renderer(this, renderingRoots, colors, selection); | |
renderer.draw(); // !!! -> we call the method object | |
} | |
drawPoint(x: number, y: number, color: Color): void { |
This file contains hidden or 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
// Step 3 | |
// !!! -> extracted interface with the things the | |
// object method uses from the original class | |
export interface PointRenderer { | |
readonly colorId: number; | |
drawPoint(x: number, y: number, color: Color): void; | |
} | |
// !!! -> the original class implements it |