File tree Expand file tree Collapse file tree 8 files changed +26
-16
lines changed
CreationalPatterns/FactoryMethod_AbstractFactory
StructuralPatterns/Delegator Expand file tree Collapse file tree 8 files changed +26
-16
lines changed Original file line number Diff line number Diff line change @@ -8,8 +8,6 @@ public Vehicle getVehicle(String name){
88 return new Audi ();
99 } else if (name .equals ("Jeep" )) {
1010 return new Jeep ();
11- } else if (name .equals ("Toyota" )) {
12- return new Toyota ();
1311 }
1412 return null ;
1513 }
Original file line number Diff line number Diff line change 11package CreationalPatterns .FactoryMethod_AbstractFactory ;
22
33public class Main {
4+ private Car car ;
45 public static void main (String [] args ) {
56 AbstractFactory abstractFactory = new AbstractFactory ();
67 Factory factory1 = abstractFactory .getFactory ("Cars" );
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11package StructuralPatterns .Delegator ;
22
3- public class Child {
3+ public class Child implements IDad , IMom {
44 private Dad dad ;
55 private Mom mom ;
66
7- public Child (){
8- this .dad = new Dad ();
9- this .mom = new Mom ();
7+ public Child (String lastName ){
8+ this .dad = new Dad (lastName );
9+ this .mom = new Mom (lastName );
1010 }
11+ @ Override
1112 public String getLastName (){
1213 return dad .getLastName ();
1314 }
Original file line number Diff line number Diff line change 11package StructuralPatterns .Delegator ;
22
3- public class Dad {
3+ public class Dad implements IDad {
44 private String lastName ;
5+ public Dad (String lastName ){
6+ this .lastName = lastName ;
7+ }
8+ @ Override
59 public String getLastName () {
610 return lastName ;
711 }
Original file line number Diff line number Diff line change 1+ package StructuralPatterns .Delegator ;
2+
3+ public interface IDad {
4+ String getLastName ();
5+ }
Original file line number Diff line number Diff line change 1+ package StructuralPatterns .Delegator ;
2+
3+ public interface IMom {
4+ String getLastName ();
5+ }
Original file line number Diff line number Diff line change 11package StructuralPatterns .Delegator ;
22
3- public class Mom {
3+ public class Mom implements IMom {
44 private String lastName ;
5+ public Mom (String lastName ){
6+ this .lastName = lastName ;
7+ }
8+ @ Override
59 public String getLastName () {
610 return lastName ;
711 }
You can’t perform that action at this time.
0 commit comments