File tree 24 files changed +333
-0
lines changed
24 files changed +333
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <classpath >
3
+ <classpathentry kind =" src" path =" src" />
4
+ <classpathentry kind =" con" path =" org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8" />
5
+ <classpathentry kind =" output" path =" bin" />
6
+ </classpath >
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <projectDescription >
3
+ <name >SWArch</name >
4
+ <comment ></comment >
5
+ <projects >
6
+ </projects >
7
+ <buildSpec >
8
+ <buildCommand >
9
+ <name >org.eclipse.jdt.core.javabuilder</name >
10
+ <arguments >
11
+ </arguments >
12
+ </buildCommand >
13
+ </buildSpec >
14
+ <natures >
15
+ <nature >org.eclipse.jdt.core.javanature</nature >
16
+ </natures >
17
+ </projectDescription >
Original file line number Diff line number Diff line change
1
+ eclipse.preferences.version =1
2
+ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode =enabled
3
+ org.eclipse.jdt.core.compiler.codegen.targetPlatform =1.8
4
+ org.eclipse.jdt.core.compiler.codegen.unusedLocal =preserve
5
+ org.eclipse.jdt.core.compiler.compliance =1.8
6
+ org.eclipse.jdt.core.compiler.debug.lineNumber =generate
7
+ org.eclipse.jdt.core.compiler.debug.localVariable =generate
8
+ org.eclipse.jdt.core.compiler.debug.sourceFile =generate
9
+ org.eclipse.jdt.core.compiler.problem.assertIdentifier =error
10
+ org.eclipse.jdt.core.compiler.problem.enumIdentifier =error
11
+ org.eclipse.jdt.core.compiler.source =1.8
Original file line number Diff line number Diff line change
1
+ package designPattern .abstractFactory ;
2
+
3
+ import designPattern .abstractFactory .zutaten .*;
4
+
5
+ public class HeidelbergZF extends ZutatenFabrik {
6
+
7
+ @ Override
8
+ public Kaese createKaese () {
9
+ return new AnalogKaese ();
10
+ }
11
+
12
+ @ Override
13
+ public Schinken createSchinken () {
14
+ return new FormVorderSchinken ();
15
+ }
16
+
17
+ @ Override
18
+ public Salami createSalami () {
19
+ return new SalamiItaliano ();
20
+ }
21
+
22
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .abstractFactory ;
2
+
3
+ import designPattern .abstractFactory .zutaten .*;
4
+
5
+ public class MannheimZF extends ZutatenFabrik {
6
+
7
+ @ Override
8
+ public Kaese createKaese () {
9
+ return new Mozarella ();
10
+ }
11
+
12
+ @ Override
13
+ public Schinken createSchinken () {
14
+ // TODO Auto-generated method stub
15
+ return new PremiumSchinken ();
16
+ }
17
+
18
+ @ Override
19
+ public Salami createSalami () {
20
+ // TODO Auto-generated method stub
21
+ return new SalamiItaliano ();
22
+ }
23
+
24
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .abstractFactory ;
2
+
3
+ public class Pizzeria {
4
+ private ZutatenFabrik zutatenFabrik ;
5
+
6
+ public void orderPizza (String location ) {
7
+ zutatenFabrik = ZutatenFabrik .getMultiton (location );
8
+ System .out .println (zutatenFabrik .createKaese ().getType ());
9
+ System .out .println (zutatenFabrik .createSalami ().getType ());
10
+ System .out .println (zutatenFabrik .createSchinken ().getType ());
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .abstractFactory ;
2
+
3
+ import java .util .HashMap ;
4
+ import designPattern .abstractFactory .zutaten .*;
5
+
6
+ public abstract class ZutatenFabrik {
7
+ private static HashMap <String , ZutatenFabrik > fabrikListe = new HashMap <>();
8
+
9
+ public ZutatenFabrik () {
10
+ fabrikListe .put ("Mannheim" , new MannheimZF ());
11
+ fabrikListe .put ("Heidelberg" , new HeidelbergZF ());
12
+ }
13
+
14
+ public static ZutatenFabrik getMultiton (String location ) {
15
+ return fabrikListe .get (location );
16
+ }
17
+
18
+ public abstract Kaese createKaese ();
19
+
20
+ public abstract Schinken createSchinken ();
21
+
22
+ public abstract Salami createSalami ();
23
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .abstractFactory .zutaten ;
2
+
3
+ public class AnalogKaese implements Kaese {
4
+
5
+ @ Override
6
+ public String getType () {
7
+ // TODO Auto-generated method stub
8
+ return "Analogkäse" ;
9
+ }
10
+
11
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .abstractFactory .zutaten ;
2
+
3
+ public class FormVorderSchinken implements Schinken {
4
+
5
+ @ Override
6
+ public String getType () {
7
+ // TODO Auto-generated method stub
8
+ return "Formvorderschinken" ;
9
+ }
10
+
11
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .abstractFactory .zutaten ;
2
+
3
+ public interface Kaese {
4
+ public abstract String getType ();
5
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .abstractFactory .zutaten ;
2
+
3
+ public class Mozarella implements Kaese {
4
+
5
+ @ Override
6
+ public String getType () {
7
+ // TODO Auto-generated method stub
8
+ return "Mozarella" ;
9
+ }
10
+
11
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .abstractFactory .zutaten ;
2
+
3
+ public class PremiumSchinken implements Schinken {
4
+
5
+ @ Override
6
+ public String getType () {
7
+ // TODO Auto-generated method stub
8
+ return "Premium Schinken" ;
9
+ }
10
+
11
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .abstractFactory .zutaten ;
2
+
3
+ public interface Salami {
4
+ public abstract String getType ();
5
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .abstractFactory .zutaten ;
2
+
3
+ public class SalamiItaliano implements Salami {
4
+
5
+ @ Override
6
+ public String getType () {
7
+ // TODO Auto-generated method stub
8
+ return "Salami Italiano" ;
9
+ }
10
+
11
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .abstractFactory .zutaten ;
2
+
3
+ public interface Schinken {
4
+ public abstract String getType ();
5
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .pizzeria ;
2
+
3
+ public class DefaultFactory extends Factory {
4
+ @ Override
5
+ public Pizza createPizza (String type ) {
6
+ switch (type ) {
7
+ case "ham" :
8
+ return new HamPizza ();
9
+
10
+ case "salami" :
11
+ return new SalamiPizza ();
12
+
13
+ case "tuna" :
14
+ return new TunaPizza ();
15
+
16
+ default :
17
+ return null ;
18
+ }
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .pizzeria ;
2
+
3
+ import java .util .ArrayList ;
4
+
5
+ public class Factory {
6
+ private static ArrayList <Factory > listOfFactories = new ArrayList <>();
7
+
8
+ protected Factory () {
9
+ listOfFactories .add (new DefaultFactory ());
10
+ listOfFactories .add (new MAFactory ());
11
+ }
12
+
13
+ public static Factory getMultiton (String location ) {
14
+ switch (location ) {
15
+ case "MA" :
16
+ return listOfFactories .get (1 );
17
+
18
+ default :
19
+ return listOfFactories .get (0 );
20
+ }
21
+ }
22
+
23
+ public Pizza createPizza (String type ) {
24
+ return null ;
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .pizzeria ;
2
+
3
+ public class HamPizza extends Pizza {
4
+
5
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .pizzeria ;
2
+
3
+ public class MAFactory extends Factory {
4
+ @ Override
5
+ public Pizza createPizza (String type ) {
6
+ switch (type ) {
7
+ case "ham" :
8
+ return new MannheimHamPizza ();
9
+
10
+ case "salami" :
11
+ return new SalamiPizza ();
12
+
13
+ case "tuna" :
14
+ return new TunaPizza ();
15
+
16
+ default :
17
+ return null ;
18
+ }
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .pizzeria ;
2
+
3
+ public class MannheimHamPizza extends Pizza {
4
+
5
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .pizzeria ;
2
+
3
+ public abstract class Pizza {
4
+
5
+ public void prepare () {
6
+ System .out .println ("I'm being prepared." );
7
+ }
8
+
9
+ public void bake () {
10
+ System .out .println ("I'm being baked." );
11
+ }
12
+
13
+ public void cut () {
14
+ System .out .println ("I'm being cut." );
15
+ }
16
+
17
+ public void pack () {
18
+ System .out .println ("I'm being packed." );
19
+ }
20
+
21
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .pizzeria ;
2
+
3
+ import java .util .Scanner ;
4
+
5
+ public class Pizzeria {
6
+ private Factory f ;
7
+
8
+ public Pizzeria (String location ) {
9
+ f = Factory .getMultiton (location );
10
+ }
11
+
12
+ public static void main (String [] args ) {
13
+ Scanner s = new Scanner (System .in );
14
+ Pizzeria p = new Pizzeria (s .nextLine ());
15
+ while (true ) {
16
+ String in = s .nextLine ();
17
+ if (!in .equals ("exit" )) {
18
+ p .orderPizza (in );
19
+ } else {
20
+ s .close ();
21
+ return ;
22
+ }
23
+ }
24
+ }
25
+
26
+ public Pizza orderPizza (String type ) {
27
+ Pizza pizza = f .createPizza (type );
28
+
29
+ if (pizza != null ) {
30
+ pizza .prepare ();
31
+ pizza .bake ();
32
+ pizza .cut ();
33
+ pizza .pack ();
34
+ } else {
35
+ System .out .println ("I'm not a pizza!" );
36
+ }
37
+
38
+ return pizza ;
39
+ }
40
+
41
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .pizzeria ;
2
+
3
+ public class SalamiPizza extends Pizza {
4
+
5
+ }
Original file line number Diff line number Diff line change
1
+ package designPattern .pizzeria ;
2
+
3
+ public class TunaPizza extends Pizza {
4
+
5
+ }
You can’t perform that action at this time.
0 commit comments