C
Chris Uppal
Oliver said:I don't know Rhino's exact requirements, but in general, the situation
he's in (again, batch job generating flat files) sounds like it would be
expressed more naturally with procedural code than object oriented code.
I don't think there's anything in the distinction between batch and on-line[*]
processing which makes one or the other more or less suited by an OO approach.
I'd agree that there's less call for OO thinking to handle a very linear
program flow (as Rhino described his program(s) to have). Perhaps that's what
you meant ?
OO's main strength is reusability [...]
I wouldn't agree with that either ;-)
With Model-View, you'd create a model object representing the document
to be generated, and pass it to a HtmlView, an AsciiView and a PdfView,
each one taking care of generating the file in the appropriate file
format.
I think that is something of an abuse of the View concept. Views (as in MVC,
and -- to a lesser degree -- as in database "views") are about individualised
renderings of a model. I don't think that the binary/text format of a PDF file
vs, say, a HTML file is a particularly fruitful application of that
flexibility. It seems to me that the aim here is to produce the /same/
document in different formats. So the abstraction that is introduced to allow
that flexibility is some sort of document writer, rather than a flavour of
View.
To try to make that clearer. Consider an extension to Rhino's requirements
where a View abstraction /would/ be fruitful. If we decide that now we want to
have different versions of the CV (aka resume) for different purposes. A short
version with no or limited contact information for posting to a website. A
version with that three-year stretch for drug smuggling elided for submitting
to government jobs ;-). And so on. That would be cause for introducing a View
abstraction. Different Views would take a Resume object, and a DocumentWriter
object, and extract a customised sub-set of the data from the Resume and send
it, possibly with modifications, to the DocumentWriter. For instance one View
might write out the description of each job that Rhino's had in chronological
order, whereas another might choose to do it in reverse-chronological order[*].
Notice how the DocumentWriter abstraction is still needed. It is no part of a
View's responsibility to know about HTML formatting or the PDF spec. The end
result is that we can generate any view of Rhino's CV in any format. Which is
nice ;-)
([*] This ability to re-order and/or reinterpret the data is what makes me
prefer to call these things "views" rather than a mere "filters".)
Of course, for one of our Views to be able to function properly, the Resume
object would have to have more structure than it has needed hitherto. Instead
of being a simple collection of paragraphs, we would probably have to introduce
more objects so that a view could ask for the various job descriptions and
their durations. It might have to be able to distinguish between contact info
and other text. And so on. All of which is more work, more complexity, and --
unless you are creating something like a job-search website, or support
software for an employment agency -- almost certainly more work than could
possibly be justified. Easier just to type the damned thing into Word(tm) and
have done. Which is a sort of answer to Rhino's earlier question about a
rule-of-thumb for when you are going over the top. If a design for something
gets to the point where it seems easier just to do without it, then you've gone
too far ;-)
-- chris