Skip to content

Instantly share code, notes, and snippets.

@MattMoony
Created May 15, 2021 15:05
Show Gist options
  • Save MattMoony/db92a28cdbc9d6b10fa28f704b674f64 to your computer and use it in GitHub Desktop.
Save MattMoony/db92a28cdbc9d6b10fa28f704b674f64 to your computer and use it in GitHub Desktop.

Revisions

  1. MattMoony created this gist May 15, 2021.
    61 changes: 61 additions & 0 deletions AutoStrategyTest.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    /*
    * Übungsbeispiel: Strategy
    * Autoren: Matthias Monschein, Nico Pessnegger
    * Datum: Mai 2021
    *
    * Beschreibung: Übungsbeispiel zum
    * Design-Pattern Strategy.
    *
    * Aufgabenstellung: Es gilt die Klassen entsprechend
    * dem Design-Pattern Strategy umzustrukturieren. Das
    * Strategy-Interface "FahrGeräusche" und die Strategies
    * "LauteGeräusche" und "LeiseGeräusche" sollen implementiert
    * werden.
    */

    abstract class Auto {
    private String name;

    public Auto(String name) {
    this.name = name;
    }

    public abstract void fahrGeräusche();

    public String getName() {
    return name;
    }
    }

    class PorscheCarrera extends Auto {
    public PorscheCarrera(String name) {
    super(name);
    }

    @Override
    public void fahrGeräusche() {
    System.out.println("BRRRRRUUUUUUUUUUUUUUUUUUUUUMMMMM");
    }
    }

    class VWGolf extends Auto {
    private float secretEmissions = (float) Math.pow(2, 32);

    public VWGolf(String name) {
    super(name);
    }

    @Override
    public void fahrGeräusche() {
    System.out.println("brrrrrrrrrrrrrrrrrrrrrrrrrrrmmm");
    }
    }

    public class AutoStrategyTest {
    public static void main(String[] args) {
    VWGolf betsy = new VWGolf("VW Golf VII - 'Betsy'");

    System.out.printf("Auto \"%s\" fährt nun los!\n", betsy.getName());
    betsy.fahrGeräusche();
    }
    }