Title: [jdjlist] Object Factory Question
Could you apply some additional separation of concerns? Must it be that it is the request object's responsibility to parse itself? It sounds to me like the responsibility of parsing and creating the object is some other object's job.
 
One other question, why would you need to cast the result of the parsing to the actual instance in the client? In other words, if you see something like;
 
XMLRequestA reqA = (XMLRequestA)RequestParser(Document doc);
 
That should probably tell you that there is a flaw in the deign. Otherwise, why have the abstract class?
-----Original Message-----
From: Greg Nudelman [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 12, 2002 12:19 PM
To: JDJList
Subject: [jdjlist] Object Factory Question

Dear Gurus:

I have an XML request coming in, I don't know what specific type. I have to parse it in order to determine that.
I have the following classes:

abstract XMLRequest
inherited by:
XMLRequestA
XMLRequestB
XMLRequestC

XMLRequest has an abstract method that all children override:
parseRequestMeat() [each one is different, of course.]
and a non-abstract method:
loadAndValidateRequestEnvelope(Document doc)
that sets a whole bunch of things in the XMLRequest, BEFORE setting up the transactionId.
loadAndValidateRequestEnvelope then calls the child's overriden parseRequestMeat(Element MEAT).

-------------------------------------------------------------------------
Now, this worked very well for XMLResponse architecture, since I knew ahead of time which object to make.  But this does not work at all in the Request:

When Document comes in, I want to instantiate something and pass it the XML Document for parsing. Trouble is, I can not instantiate the XMLRequest object, nor can I instantiate the XMLRequestA or B because I do not know ahead of time which object it will be... not until I can get the transactionId, to get which I must call loadAndValidateRequestEnvelope(Document doc) on something.

I can use the static XMLRequest req = XMLRequestFactory.getXMLRequest(Document doc);
and then cast it as the appropriate object:

(XMLRequestA)req

but I can't seem to set up anything in the loadAndValidateRequestEnvelope before I instantiate the correct Request.  I guess I can write another method and get the transactionId first, then have a case statement in the factory which decides which (A, B, C) to create.  Is this the "only" way? Or am I missing something "trivial" in the design?

Any ideas/hints are appreciated.

Greg

To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm
To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm

Reply via email to