The Artima Developer Community
Sponsored Link

Java Answers Forum
Why static this abstract factory?

1 reply on 1 page. Most recent reply: Jun 26, 2002 8:13 PM by Karl Laird

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
kwanghui

Posts: 1
Nickname: burn
Registered: Jun, 2002

Why static this abstract factory? Posted: Jun 20, 2002 6:52 AM
Reply to this message Reply
Advertisement
abstract class ShapeFactory {
private static Map factories = new HashMap();
public static void addFactory(String id,ShapeFactory f) {factories.put(id, f);}
}
}
//===============================================
abstract class jub3 {
private static class Factory extends ShapeFactory {
protected Object create() { return new someClass(); }
}

why do I add the static here?
Will it increase or fasten my performance?
Is this the best way to write the code?

static { ShapeFactory.addFactory("jub3", new Factory());}
};

Thanks
KH


Karl Laird

Posts: 2
Nickname: iiq374
Registered: Jun, 2002

Re: Why static this abstract factory? Posted: Jun 26, 2002 8:13 PM
Reply to this message Reply
It is not a performance issue so much as a getting the design pattern to work problem. By making it static it means that all instances are sharing the same hashmap - which means that they can all actually find the factories just by creating an abstract factory and grabbing one out of the hashmap (presuming something else has initialised the factories) This greatly eases the burdern of parenthood seeking.

Flat View: This topic has 1 reply on 1 page
Topic: Installing web app on WebSphere 4.0.3 Previous Topic   Next Topic Topic: socket.getInputStream->xml Document

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use