Created
May 15, 2021 15:05
-
-
Save MattMoony/db92a28cdbc9d6b10fa28f704b674f64 to your computer and use it in GitHub Desktop.
Revisions
-
MattMoony created this gist
May 15, 2021 .There are no files selected for viewing
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 charactersOriginal 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(); } }