我理解是:
DBForum是DBForumFactory的一个产品,产品接口是Forum,如果我们使用XML来存储forum,那么我们可以做一个XMLForum的具体产品,然后由DBForumFactory生产。
在DBForum中构造函数中放置数据库查询,我认为这是他不得已为之,不是好方法,我们看代码:
/** * Creates a new forum with the specified name and description. * * @param name the name of the forum. * @param description the description of the forum. * @param factory the DbForumFactory the forum is a part of. */ protected DbForum(String name, String description, DbForumFactory factory) { this.id = SequenceManager.nextID(JiveGlobals.FORUM); this.name = name; this.description = description; long now = System.currentTimeMillis(); creationDate = new java.util.Date(now); modifiedDate = new java.util.Date(now); this.factory = factory; insertIntoDb(); properties = new Hashtable(); init(); }
/** * Loads a forum with the specified id. */ protected DbForum(long id, DbForumFactory factory) throws ForumNotFoundException { this.id = id; this.factory = factory; loadFromDb(); init(); }
|
第一个构造函数比较轻便,为了和第一个性质相同,第二个构造函数给我感觉是赶鸭子上场,另外也可能原作者认为在这里无需做得太漂亮,如果这里再使用工厂,无疑有乱用模式之嫌疑。
第二个构造函数虽然表面上简洁,但是loadFromDb();很复杂。我认为这是
败笔,Jive有三个败笔,一是Jsp端乱;二是用户权限系统差;三是数据库操作和Jsp端一样的乱。
优点是:使用设计模式架构了整个系统;缓冲机制。