?
Solved

Classes Question

Posted on 2006-07-18
4
Medium Priority
?
311 Views
Last Modified: 2013-11-23
I have a class

Properties:
CompanyName
CompanyURL
ArrayIndexNumber
ReqeustXML
ResponseXML

Methods:
CreateXMLRequest
SendReceive ??? (This is what the question is about)

Its a web app so each time a user runs the page, 6 of these class objects are created in an object array (one for each company).  Each object knows its position in the array through the ArrayIndexNumber property.  The CreateXMLRequest method adds the RequestXML property.

Now my original plan was to do this:

As each object is created (in a loop), the SendReceive method is started on a separate thread and will post RequestXML off to the appropriate CompanyURL.  Because of the way you send information to a thread (you pass an instantiated object), I thought that SendReceive should be a sub routine outside the class which will receive each of the objects in the array as they are created.  This is the reason for instantiating the object with its ArrayIndex number so that it knows which position in the array it should go back to.

So my feelings are that the SendReceive method should remain outside the class.

However, my colleague (he's writing the app) has put the SendReceive method inside the class so this is what is happening at the moment:

Loop Starts
  ObjectInstance Instantiated in array
  ObjectInstance Passed to ObjectInstance.SendReceive method (this is how)
           (threadpool.queueuserworkitem(addressof ObjectArray(i).SendReceive,ObjectArray(i))
Next

So you are passing the object back to itself???  Is this OK?  

Would appreciate some other opinions on this as it somehow does not seem right to me.

If u need further info, please ask

Wing
0
Comment
Question by:WingYip
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 21

Expert Comment

by:MogalManic
ID: 17129115
Having SendRecieve on the class doesn't look like a problem to me.  With this method you can remove the 2nd parameter [ObjectArray(i)].  This is because the SendRecieve() method already points to the instance in the 'this' pointer ('me' if you are using vb).  So basically the object knows how to send itself.

0
 
LVL 1

Author Comment

by:WingYip
ID: 17129526
Thanks.  Point taken.  However, if the SendReceive method amounted to a 100 or so lines of code, wouldn't you be adding to the size of your class objects in memory (as opposed to having one proc that processes all classes?  Does this in fact matter particularly?

Wing

0
 
LVL 21

Accepted Solution

by:
MogalManic earned 750 total points
ID: 17130018
The actual Send/Recieve functionality should be controled by a "helper" class.  The pattern I'm thinging of is "inversion of control" (see http://en.wikipedia.org/wiki/Inversion_of_Control).  

You would create an interface for Send/Recieve.  Then have the class point to a particular implementation of the interface (I.E. Send/Recieve using HTTP protocol) to do the actual work.

Then for testing the class (using jUnit(http://www.junit.org/index.htm) or nUnit(http://www.nunit.org/) or something simalar), the test class can "inject" a test Send/Recieve class that doesn't rely on acually "sending" the object, just verifying the object is constructed properly.  This way the class can be tested without relying on the Send/Recieve actually working (you would not want to send "test" data to the companyURL).

The HTTP implementation of Send/Recieve would be tested seperatly without relience on other classes.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Starting up a Project
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question