Created
August 8, 2012 22:32
-
-
Save egonelbre/3299448 to your computer and use it in GitHub Desktop.
Foo java
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
// V1 | |
public class Foo { | |
} | |
public class KungFoo extends Foo { | |
public KungFoo(string owner){ | |
// ... | |
} | |
} | |
public class FooBarred extends Foo { | |
public FooBarred(string owner){ | |
// ... | |
} | |
} | |
public class FooKing extends Foo { | |
public FooKing(string owner){ | |
// ... | |
} | |
} | |
public Foo createFoo(Class fooClass, string owner = "Bar"){ | |
Foo myFoo = new fooClass(owner); | |
// some additional handling | |
return myFoo; | |
} | |
// V2 | |
// can be implemented with method passing in Java8 | |
public abstract class FooSpec { | |
public void init(Foo f); | |
} | |
public class KungFoo extends FooSpec { | |
public void init(Foo f){ | |
// ... | |
} | |
} | |
public class FooBarred extends FooSpec { | |
public void init(Foo f){ | |
// ... | |
} | |
} | |
public class FooKing extends FooSpec { | |
public void init(Foo f){ | |
// ... | |
} | |
} | |
public Foo createFoo(FooSpec fooSpec, string owner = "Bar"){ | |
Foo myFoo = new Foo(owner); | |
fooSpec.init(myFoo); | |
// some additional handling | |
return myFoo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment