title: Composition and Aggregation referencing the same class (UML / TypeScript)
body: <p>Is it possible and does it make sense that Hero has an aggregation and composition relationship? </p>
  
  <p>My aim is to keep a list of powers for each hero, however when creating one it should only be possible to add one Power instead of multiple Powers. That is the reason why I've created a private attribute power for only one power.</p>
  
  <p>My question is about the validity of the UML class diagram. Is that the correct way of displaying my intend?</p>
  
  <p>The reason why power is an aggregation is that it could be that another class uses the same power instance (I have implemented some cache which always return the same instance of a power, for simplicity I didn't show that part).</p>
  
  <p>The reason why powers is an composition is that it strongly depends on the hero instance. If hero is destroyed, powers should also be cleaned.</p>
  
  <p><a href="https://i.stack.imgur.com/CQxNK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CQxNK.png" alt="Hero UML Composition, Aggregation"></a></p>
  
  <p>The code for the UML does look like something like that (TypeScript):</p>
  
  <p>hero.ts</p>
  
  <pre><code>import { Power } from './power';
  
  export class Hero {
    powers: Power[] = [];
  
    constructor(private power?: Power) {
      if (power) {
        this.addPower(power);
      }
    }
  
    addPower(power: Power) {
      this.powers.push(power);
    }
  
  }
  </code></pre>
  
  <p>power.ts</p>
  
  <pre><code>export class Power {
    constructor(private title: string) { }
  }
  </code></pre>