forked from Asiatik/codezilla
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Abstract Factory): added new Implementation for Abstract Factory…
… in Java (Asiatik#186)
- Loading branch information
1 parent
9f3642a
commit 7b985f2
Showing
11 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
public class App{ | ||
|
||
/** | ||
* | ||
* Here is used a implementation Abstract Factory | ||
* | ||
* */ | ||
public static void main( String[] args ){ | ||
|
||
FactoryCar factory; | ||
|
||
//Using firt implementations | ||
factory = new GMCFactory(); | ||
printInformations(factory); | ||
|
||
//Using second implementation | ||
factory = new ToyotaFactory(); | ||
printInformations(factory); | ||
} | ||
|
||
public static void printInformations(FactoryCar factory) { | ||
|
||
Minivan minivan = factory.createMinivan(); | ||
System.out.println("------- Info MiniVan---------"); | ||
minivan.printName(); | ||
minivan.printFuel(); | ||
System.out.println("-----------------------------"); | ||
|
||
Pickup pickup = factory.createPickup(); | ||
System.out.println("------- Info Pickup---------"); | ||
pickup.printName(); | ||
pickup.printFuel(); | ||
System.out.println("-----------------------------"); | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public interface FactoryCar { | ||
|
||
Minivan createMinivan(); | ||
Pickup createPickup(); | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class GMCFactory implements FactoryCar { | ||
|
||
public Minivan createMinivan() { | ||
|
||
return new Savana(); | ||
} | ||
|
||
public Pickup createPickup() { | ||
|
||
return new Sierra(); | ||
} | ||
|
||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public interface Minivan { | ||
|
||
public void printName(); | ||
public void printFuel(); | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public interface Pickup { | ||
|
||
public void printName(); | ||
public void printFuel(); | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class Savana implements Minivan { | ||
|
||
public void printName() { | ||
System.out.println("Savana 1500 Cargo"); | ||
|
||
} | ||
|
||
public void printFuel() { | ||
System.out.println("Flex"); | ||
|
||
} | ||
|
||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class Sienna implements Minivan { | ||
|
||
public void printName() { | ||
|
||
System.out.println("Sienna"); | ||
} | ||
|
||
public void printFuel() { | ||
|
||
System.out.println("Gasoline"); | ||
} | ||
|
||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class Sierra implements Pickup { | ||
|
||
public void printName() { | ||
|
||
System.out.println("GMC Sierra 1500 SLT Ext. Cab 4WD"); | ||
} | ||
|
||
public void printFuel() { | ||
|
||
System.out.println("Flex"); | ||
} | ||
|
||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class Tacoma implements Pickup { | ||
|
||
public void printName() { | ||
|
||
System.out.println("TACOMA"); | ||
} | ||
|
||
public void printFuel() { | ||
|
||
System.out.println("Diesel"); | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class ToyotaFactory implements FactoryCar { | ||
|
||
public Minivan createMinivan() { | ||
|
||
return new Sienna(); | ||
} | ||
|
||
public Pickup createPickup() { | ||
|
||
return new Tacoma(); | ||
} | ||
|
||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Abstract Factory | ||
|
||
Has primary responsibility for reducing the use of `new`, this pattern provide a interface to create a family objects. | ||
|
||
How in example we have a family of Car( Minivan and Pickups ), but can have several implementations how: | ||
|
||
- ToyotaFactory | ||
- GMCFactory | ||
|
||
With this pattern we can create any CarFactory, just implemented it. | ||
|
||
See follow classes: | ||
|
||
- `FactoryCar` | ||
- `MiniVan` | ||
- `Pickup` | ||
- Implementations for `Minivan` and `Pickup` | ||
- `GMCFactory` | ||
- `ToyotaFactory` |