Created
May 11, 2017 05:28
-
-
Save leogtzr/499ae54dd660386a9f61e4d00bf56b16 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// @leonidasgtzr | |
interface TV { | |
void show(); | |
} | |
class ColorTV implements TV { | |
@Override | |
public void show() { | |
System.out.println("Showing content with Color ... "); | |
} | |
} | |
class LedTV implements TV { | |
@Override | |
public void show() { | |
System.out.println("Showing content with Leds ..."); | |
} | |
} | |
enum TVFactory_2 { | |
COLOR(ColorTV.class), | |
LED(LedTV.class) | |
; | |
private final Class<? extends TV> tv; | |
TVFactory_2(final Class<? extends TV> tv) { | |
this.tv = tv; | |
} | |
public TV create() { | |
TV theTv = null; | |
try { | |
theTv = tv.newInstance(); | |
} catch (final Exception ex) {} | |
return theTv; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment