From: Steffen P. <ste...@gm...> - 2005-12-01 07:38:12
|
Hi, > > AuthorProfileFactory? This sounds like the classic situation for a > > factory > > pattern. > > This implies that you have an AuthorProfile class with many > instances. Can we do without? Why would we want to? Creating these objects is a one time task, just as parsing the cvs log file, and should be done on start up. IMHO a simple Profile class with a couple of getters and setters will do the job. But while we are at it, we may want to go with an interface that specifies the get methods and provide a default implementation that has the setters as well. > > Presentation layer classes would merely need to call > > Author.getProfile() > > and then render that profile any way they like. > > That's where I disagree. I'd prefer the log parsing and > representation to make no assumptions about the application that uses > the data. Having Author.getProfile() would add such an assumption to > the log representation. Yes, I certainly agree. The profile stuff should be kept separate from the model code as there is no apparent connection to the cvs log. > I want to be able to re-use the low-level > classes (like Author) without having a dependency that forces me to > drag higher-level classes (like the Profile stuff) into my new project. Exactly. StatCvs-XML which shares the model code has a very different approach to the profile . For maven we have a straight forward dom parser that stores results in a map of maps. SAXBuilder builder = new SAXBuilder(); Document suite = builder.build(file); Element element = suite.getRootElement().getChild("developers"); if (element != null) { for (Iterator it = element.getChildren().iterator(); it.hasNext();) { Element developer = (Element)it.next(); String id = developer.getChildText("id"); if (id == null) { continue; } if (developer.getChildText("name") != null) { settings.setFullname(id, developer.getChildText("name")); } if (developer.getChildText("image") != null) { settings.setAuthorPic(id, developer.getChildText("image")); } else if (developer.getChildText("url") != null) { settings.setAuthorPic(id, developer.getChildText("url") + "/" + id + ".png"); } } } If anyone were to define a profile class I would probably go ahead and refactor the code though :). Steffen |