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
import { RecipeComponent } from "./recipe-component"; | |
export class Recipe implements RecipeComponent { | |
name: string; | |
components: RecipeComponent[] = []; | |
constructor(name: string) { | |
this.name = name; | |
} |
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
import { RecipeComponent } from "./recipe-component"; | |
export class Ingredient implements RecipeComponent { | |
name: string; | |
amount: string; | |
constructor(name: string, amount: string) { | |
this.name = name; | |
this.amount = amount; | |
} |
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 interface RecipeComponent { | |
showDetails(): string; | |
} |
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
import { Ingredient } from "./ingredient"; | |
import { Recipe } from "./recipe"; | |
const ingredient1 = new Ingredient("Flour", "2 cups"); | |
const ingredient2 = new Ingredient("Eggs", "3"); | |
const recipe = new Recipe("Cake"); | |
recipe.addIngredient(ingredient1); | |
recipe.addIngredient(ingredient2); | |
const ingredient3 = new Ingredient("Milk", "1 cup"); |
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
import { Ingredient } from './ingredient'; | |
export class Recipe { | |
name: string; | |
ingredients: Ingredient[] = []; | |
recipes: Recipe[] = []; | |
constructor(name: string) { | |
this.name = name; | |
} |
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 Ingredient { | |
name: string; | |
amount: string; | |
constructor(name: string, amount: string) { | |
this.name = name; | |
this.amount = amount; | |
} | |
showDetails(): string { |
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
import { Component } from "./component"; | |
import { Composite } from "./composite"; | |
import { Leaf } from "./leaf"; | |
const leaf1: Component = new Leaf(); | |
const leaf2: Component = new Leaf(); | |
const leaf3: Component = new Leaf(); | |
const composite1: Component = new Composite(); | |
const composite2: Component = new Composite(); |
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
import { Component } from "./component"; | |
export class Composite implements Component { | |
private children: Component[] = []; | |
// Add a child to the list of children | |
addChild(child: Component): void { | |
this.children.push(child); | |
} |
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
import { Component } from "./component"; | |
export class Leaf implements Component { | |
operation(): void { | |
console.log("Leaf operation."); | |
} | |
} |
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 interface Component { | |
operation(): void; | |
} |