Re: [Htmlparser-developer] toPlainTextString() feedback requested
Brought to you by:
derrickoswald
From: Joshua K. <jo...@in...> - 2002-12-24 05:40:22
|
> Could you explain why you want to refactor these methods? Remember the > danger of premature refactoring ... you lose flexibility that then has > to be re-added later on, making more work in the long run. Hi Sam, There's a good deal of duplicate code in way the two toHTML methods and the toPlainTextString method do their work. The central theme is information accumulation/alteration. That involves outputing tag and node results and recusing through tags. The refactoring to Visitor allows us to * remove many lines of duplicate code, spread across many classes * remove hard-coded accumulation/alteration logic, thereby making it easier for clients to get the data they need Visitor takes some getting used to. I rarely use the pattern. In this case, IMO, it was a good fit. > Is there some efficiency reason why you want to refactor these methods > or is it just for neatness? Duplication removal is reason #1. Removal of hard-coded logic is reason #2. Simplicity is reason #3: there is little reason to fatten the interfaces of tag and node classes with various data accumulation/alteration methods when one method and a variety of concrete Visitors can do the job with much less code. best regards jk |