To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm-----Original Message-----
From: Baker, Jay [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 12, 2002 10:35 AM
To: JDJList
Subject: [jdjlist] RE: Object Factory QuestionCould 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?To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm-----Original Message-----
From: Greg Nudelman [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 12, 2002 12:19 PM
To: JDJList
Subject: [jdjlist] Object Factory QuestionDear 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
XMLRequestCXMLRequest 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
Title: [jdjlist] Object Factory Question
Jay,
thank you very much for your post. This is doing wonders to get my
mind unstuck!! :-)
1)
>>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.
I
think this is a great idea! Does anyone else have any experience with XML
Data binding objects parsing/creating themselves? OR using other classes
to do it? Comments are most welcome.
2)
>>That should probably tell you that there is a flaw in the
design
I do not believe this there to be a flaw with
the design of inheritance (although there are MOST DEFINITELY flaws
elsewhere).
The
reason for this is that all the XML Requests I receive will be wrapped in a
standard envelope which includes useful items like time of request, version, who
sent it, etc. All this is to be handled by the XMLRequest attributes. The
specific meat of the request is to handled individually with XMLRequestA, B,
C. Like I said, this works great for CREATING these type of requests,
however, parsing is another issue... I am starting to think that having another
class doing the parsing is a great idea.
3)>>why have the abstract class?
The
reason the class is abstract, is that I never expect to have "Just XMLRequest"
-- this construct has no meaning, so it is abstract. Yes, I know
composition with XMLRequest[Envelope] class would have worked too, maybe even
work better for some things.
4)
>>XMLRequestA reqA = (XMLRequestA)RequestParser(Document
doc);
I believe it is more like XMLRequest req = new
XMLRequestA(doc); then passing it to the server's
saveRequestMakeResponse(XMLRequest
req);
Thanks again,
Greg
- [jdjlist] RE: Object Factory Question Baker, Jay
- [jdjlist] RE: Object Factory Question Greg Nudelman
- [jdjlist] RE: Object Factory Question Greg Nudelman
