Reflection Free Factories in Java

2,418 views
2,178 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
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,418
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
32
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

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…

×