-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f84d44
commit 52b9097
Showing
17 changed files
with
186 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
Creational_Pattern/Factory_Method/Java_Factory_Method/Client.java
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,8 @@ | ||
package Creational_Pattern.Factory_Method.Java_Factory_Method; | ||
|
||
public class Client { | ||
public static void main(String[] args) { | ||
Transport transport = TransportFactory.getTransport(TransportType.SHIP); | ||
transport.deliver(); //SeaTransport | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
Creational_Pattern/Factory_Method/Java_Factory_Method/Ship.java
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,8 @@ | ||
package Creational_Pattern.Factory_Method.Java_Factory_Method; | ||
|
||
class Ship implements Transport { | ||
@Override | ||
public void deliver() { | ||
System.out.println("SeaTransport"); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Creational_Pattern/Factory_Method/Java_Factory_Method/Transport.java
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 @@ | ||
package Creational_Pattern.Factory_Method.Java_Factory_Method; | ||
|
||
interface Transport{ | ||
void deliver(); | ||
} |
16 changes: 16 additions & 0 deletions
16
Creational_Pattern/Factory_Method/Java_Factory_Method/TransportFactory.java
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,16 @@ | ||
package Creational_Pattern.Factory_Method.Java_Factory_Method; | ||
|
||
class TransportFactory{ | ||
private TransportFactory() { } | ||
|
||
public static final Transport getTransport(TransportType transportType) { | ||
switch (transportType) { | ||
case TRUCK: | ||
return new Truck(); | ||
case SHIP: | ||
return new Ship(); | ||
default: | ||
throw new IllegalArgumentException("This Transport type is unsupported"); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Creational_Pattern/Factory_Method/Java_Factory_Method/TransportType.java
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 @@ | ||
package Creational_Pattern.Factory_Method.Java_Factory_Method; | ||
|
||
public enum TransportType{ | ||
TRUCK, SHIP | ||
} |
8 changes: 8 additions & 0 deletions
8
Creational_Pattern/Factory_Method/Java_Factory_Method/Truck.java
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,8 @@ | ||
package Creational_Pattern.Factory_Method.Java_Factory_Method; | ||
|
||
class Truck implements Transport { | ||
@Override | ||
public void deliver() { | ||
System.out.println("RoadTransport"); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
Creational_Pattern/Factory_Method/Kotlin_Factory_Method/Ship.kt
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,7 @@ | ||
package Creational_Pattern.Factory_Method.Kotlin_Factory_Method | ||
|
||
class Ship : Transport { | ||
override fun deliver() { | ||
println("SeaTransport") | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Creational_Pattern/Factory_Method/Kotlin_Factory_Method/Transport.kt
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 @@ | ||
package Creational_Pattern.Factory_Method.Kotlin_Factory_Method | ||
|
||
interface Transport { | ||
fun deliver() | ||
} |
10 changes: 10 additions & 0 deletions
10
Creational_Pattern/Factory_Method/Kotlin_Factory_Method/TransportFactory.kt
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,10 @@ | ||
package Creational_Pattern.Factory_Method.Kotlin_Factory_Method | ||
|
||
class TransportFactory { | ||
companion object { | ||
fun getTransport(type: TransportType) : Transport = when(type) { | ||
TransportType.TRUCK -> Truck() | ||
TransportType.SHIP -> Ship() | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Creational_Pattern/Factory_Method/Kotlin_Factory_Method/TransportType.kt
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 @@ | ||
package Creational_Pattern.Factory_Method.Kotlin_Factory_Method | ||
|
||
enum class TransportType { | ||
TRUCK, SHIP | ||
} |
7 changes: 7 additions & 0 deletions
7
Creational_Pattern/Factory_Method/Kotlin_Factory_Method/Truck.kt
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,7 @@ | ||
package Creational_Pattern.Factory_Method.Kotlin_Factory_Method | ||
|
||
class Truck : Transport { | ||
override fun deliver() { | ||
println("RoadTransport") | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Creational_Pattern/Factory_Method/Kotlin_Factory_Method/main.kt
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,6 @@ | ||
package Creational_Pattern.Factory_Method.Kotlin_Factory_Method | ||
|
||
fun main() { | ||
val transport = TransportFactory.getTransport(TransportType.TRUCK) | ||
transport.deliver() // RoadTransport | ||
} |