Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. Factory
  2. {
  3. //real case invoking
  4. invokeSharedCode(new BikeFactory());
  5. invokeSharedCode(new CarFactory());
  6. }
  7.  
  8. //object being created depending on factory type, and behavior is defined in interface also
  9. public static void invokeSharedCode(TransportFactory factory){
  10. Transport transport = factory.create();
  11. System.out.println(transport.drive());
  12. }
  13.  
  14. Shared code interface not hardcoded with typeA or typeB,
  15. but typeA and B all extend the same factory and initialization using same function.
  16. After create, we can invoke the same name function provided by typeA or B.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement