Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Reflection-free Factories in Java A functional programmer’s take on generics!
A Java Factory
A Java 2 Factory
Problems
A Car Designer…
A Designed Car
Dave, the Car painter <ul><li>class  Red<T  extends  Car> extends Car { </li></ul><ul><li>public   static   class  Designe...
Finally…
Upcoming SlideShare
Loading in …5
×

Reflection Free Factories in Java

2,508 views

Published on

A method of applying the factory pattern in Java that allows the creation of generic objects and avoids the standard Reflection issues: exceptions from abstract classes and classes missing nullary constructors.

Published in: Technology, News & Politics
  • Be the first to comment

Reflection Free Factories in Java

  1. 1. Reflection-free Factories in Java A functional programmer’s take on generics!
  2. 2. A Java Factory
  3. 3. A Java 2 Factory
  4. 4. Problems
  5. 5. A Car Designer…
  6. 6. A Designed Car
  7. 7. Dave, the Car painter <ul><li>class Red<T extends Car> extends Car { </li></ul><ul><li>public static class Designer<T extends Car> </li></ul><ul><li>implements Car.Designer<Red<T>> { </li></ul><ul><li>public Designer(T.Designer<T> jeff) { </li></ul><ul><li>… </li></ul><ul><li>} </li></ul><ul><li>public Red<T> build() { </li></ul><ul><li>return new Red<T>(jeff.build()); </li></ul><ul><li>} </li></ul><ul><li>… </li></ul><ul><li>public static final <T extends DesignedCar> Designer<T> </li></ul><ul><li>dave(T.Designer<T> jeff) { </li></ul><ul><li>return new Designer<T>(jeff); </li></ul><ul><li>} </li></ul>
  8. 8. Finally…

×