Skip to content

Instantly share code, notes, and snippets.

@leogtzr
Created May 11, 2017 05:28
Show Gist options
  • Save leogtzr/499ae54dd660386a9f61e4d00bf56b16 to your computer and use it in GitHub Desktop.
Save leogtzr/499ae54dd660386a9f61e4d00bf56b16 to your computer and use it in GitHub Desktop.
// @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