Comments inline...
On 6/17/06, Allen Gilliland <[EMAIL PROTECTED]> wrote:
Dave Johnson wrote:
> On 6/16/06, Allen Gilliland <[EMAIL PROTECTED]> wrote:
>> I am thinking that we could modify that init() method to this ...
>>
>> public void init(Map data) throws ModelInitializationException;
>
>> ... this way whatever piece of code is initializing that page
model can
>> pass in a set of data that may be useful to the page model. We also
>> allow the page model to throw an exception during init if somehow the
>> page model doesn't receive all the data it needs or something else
bad
>> happens during init.
>>
>> think that makes sense?
>
> I don't think we can anticipate all of the things that a page model
> author will need to access within a model and using a request here
> stikes a good balance. Authors have access to the request and at the
> same time we can provide access to request related things like the
> parsed WeblogPageRequest object via request attibutes.
I agree, we can't anticipate everything that a page model would need,
but to me that is more of a reason to give it mode data than less data.
I definitely think that the original request will still go in the Map
of data passed into each page model, but using the Map instead of just
the request has a couple benefits in my mind ...
The request attribute already give us a map: request attributes.
1. It's extensible. If at any time in the future we decide that each
page model should have something else at init time then it's trivial to
add it. Using just the request means we would have to refactor the
interface and all implementors to fit the need.
Could use request attributes, that's what they're for.
2. Custom implementations have more options. What if someone wants to
create their own servlet to add some functionality that we don't provide
and they create a custom page model for it? What if they want that page
model to be initialized with more data. Using a Map makes that easy
because the code that constructs the page model can pass in any data
they want.
3. It's more efficient. In many cases a servlet or other code will
already have done some parsing/validation on the request before the page
model is constructed. Why force that work to be duplicated? By letting
additional objects be passed into the init method we can reduce
redundant work like parsing the request, looking up pojos like the
Website object, etc.
The model could just pull a parsed WeblogRequest object from the
request attributes.
I would have added "easier unit testing" as an advantage to using a
Map, but the fact that all page models need the request negates that
advantage.
So I think I am still a fan of using a Map instead of just the servlet
request for page model init. I don't think there is anything to lose by
doing it. We could alternatively have the init method be init(request,
Map data), so the page model is guaranteed to get the request and the
Map is purely optional extra data.
I really don't like the idea of sticking the request in a map.
So if you insist on a map, I'd like to do as you suggest:
init(request, Map)