The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Decorator pattern

I've got a (rather simple) task in front of me (well, not really today, I'm just curious) : I have to search a word in a text. But the text can come in various formats ; for example: plain text in German, XML in Greek, ...
Since I don't want the search to depend on the formats, I'm considering using the decorator pattern to filter the "real" text (not unlike java IO classes). Then I'd have just a stream of characters to search, no matter where they came from.
This looks fine and dandy, everything is nicely decoupled, but reality strikes back : I must keep the position in the original file, in order to do anything useful.
This looks like coupling is coming back. Is the decorator pattern plainly inadapted, or am I renouncing too early ?
Tuesday, December 14, 2004
when I did such a task once, I slipped tokens that were ignored by the search but allowed me to map back to statement-points in the source file.

If you are streaming live, then the stream that eats your complex format and sh*ts your plaintext does know (roughly) where it is upto in the source-side.  You can always ask it.
i like i
Wednesday, December 15, 2004
I don't think you'll be able to handle XML files in this manner - they have to be parsed so that entities will resolve properly. You can't tell in advance if your content will contain ä or ä or ä directly.
Richard Rodger Send private email
Wednesday, December 15, 2004
Thanks for the answer ; "i like i", you mean that my filters should provide in their interface some function that would return the current position, for each char they spit. Or maybe give a pair (char, position) as an output. Or even give a start and end position for each character, since (as Richard pointed out), a character can span several positions in XML.
Thus I'd just change the contents of my streams, while keeping the same structure.
Wednesday, December 15, 2004

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz