Solved

Classes Question

Posted on 2006-07-18
4
296 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
  • 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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now