Created
June 11, 2024 11:03
-
-
Save Caballerog/da2cf62e8348621ac115808dae57566e to your computer and use it in GitHub Desktop.
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(); | |
// Build the tree structure | |
(composite1 as Composite).addChild(leaf1); | |
(composite1 as Composite).addChild(leaf2); | |
(composite2 as Composite).addChild(leaf3); | |
(composite2 as Composite).addChild(composite1); | |
// Call the operation on the root composite | |
composite2.operation(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment