Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. public static void addFactoryImpl(Class impl) { }
  2.  
  3. BugReportFactory.addFactoryImpl(new BugReportFactoryAndroid());
  4.  
  5. private static IBugReportFactory INSTANCE = null;
  6. public static void addFactoryImpl(Class impl) {
  7. INSTANCE = (IBugReportFactory)impl;
  8. }
  9.  
  10. BugReportFactory.addFactoryImpl(new BugReportFactoryAndroid().getClass());
  11.  
  12. BugReportFactory.addFactoryImpl(BugReportFactoryAndroid.class);
  13.  
  14. private static IBugReportFactory INSTANCE = null;
  15. public static void addFactoryImpl(Class impl) {
  16. INSTANCE = (IBugReportFactory)impl;
  17. }
  18.  
  19. private static Class INSTANCE = null;
  20. public static void addFactoryImpl(Class impl) {
  21. INSTANCE = impl;
  22. }
  23.  
  24. BugReportFactory.addFactoryImpl(BugReportFactoryAndroid.class);
  25.  
  26. BugReportFactory.addFactoryImpl(BugReportFactoryAndroid.class);
  27.  
  28. BugReportFactory.addFactoryImpl((new BugReportFactoryAndroid()).getClass());
  29.  
  30. BugReportFactory.addFactoryImpl(BugReportFactoryAndroid.class);
  31.  
  32. public static void addFactoryImpl(Object impl) { }
  33.  
  34. public static <T> void addFactoryImpl(T impl) { }
  35.  
  36. public interface BugReportFactory {
  37. public A createA();
  38. public B createB();
  39. }
  40.  
  41. public class BugReportFactoryAndroid implements BugReportFactory {..}
  42.  
  43. public class BugReportFactoryIOS implements BugReportFactory {..}
  44.  
  45. public class Foo {
  46. private List<BugReportFactory> factories = new ArrayList<BugReportFactory>();
  47.  
  48. public void addFactoryImpl(BugReportFactory factory) {
  49. factories.add(factory);
  50. }
  51.  
  52. public void createAll() {
  53. for (BugReportFactory f : factories) {
  54. A a = f.createA();
  55. B b = f.createB();
  56. ...
  57. }
  58. }
  59. }
  60.  
  61. private static IBugReportFactory INSTANCE = null;
  62. public static void addFactoryImpl(Class<?> impl) {
  63. Object factoryImpl = null;
  64. try {
  65. factoryImpl = impl.newInstance();
  66. } catch (InstantiationException e) {
  67. // TODO Auto-generated catch block
  68. e.printStackTrace();
  69. } catch (IllegalAccessException e) {
  70. // TODO Auto-generated catch block
  71. e.printStackTrace();
  72. }
  73. INSTANCE = (IBugReportFactory) factoryImpl;
  74. }
  75.  
  76. BugReportFactory.addFactoryImpl(BugReportFactoryAndroid.class);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement