diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2017-02-16 12:15:03 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2017-02-16 12:15:03 +0100 |
commit | 7cd57266593fe7cb9e08140f4405a93dd5c58303 (patch) | |
tree | 3cc07b965676b6dd9c1b8695e13a7399c741b5d1 /java | |
parent | f389c94ddb8b9477741aafda6dd141e3c04cea3d (diff) | |
download | share-7cd57266593fe7cb9e08140f4405a93dd5c58303.zip share-7cd57266593fe7cb9e08140f4405a93dd5c58303.tar.gz |
java : add PatternFactory.java
Diffstat (limited to 'java')
-rw-r--r-- | java/PatternFactory.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/java/PatternFactory.java b/java/PatternFactory.java new file mode 100644 index 0000000..e137efe --- /dev/null +++ b/java/PatternFactory.java @@ -0,0 +1,39 @@ + +abstract class Human +{ + enum Gender { MALE, FEMALE } + abstract protected Gender construct(); + private Gender g; + + public Human() { + g = construct(); + } + + public void say() + { + System.out.println("I am a " + g); + } +} + +class Female extends Human +{ + @Override + protected Gender construct() { return Gender.FEMALE; } +} + +class Male extends Human +{ + @Override + protected Gender construct() { return Gender.MALE; } +} + + +public class PatternFactory { + + public static void main (String [] args ) + { + (new Female()).say(); + (new Male()).say(); + } +} + |