Simple enough, right? But it's very easy to end up with a bad design, simply because, well, where do you start? What does this program really look like?
The idea is to have a Worker object handle each line, which will pass the line to a Parser object. The Worker will ask the Parser if the data is ready to be collected, and if it is, then the Worker will collect the data and do something with it.
This is the rough program skeleton, in Java pseudo-code:
That's the main outline. Everything can be easily built on top of that.
Notes:
- dataReady() is very good design, because it allows the parser to get the data in blocks of 2 or 3 or k at a time. If you were to handle the data immediately after each line was parsed, then you could only handle a block of 1!
Thanks to:
- Anthony Guo for reading drafts of this post.
No comments:
Post a Comment