Solved

Classes Question

Posted on 2006-07-18
4
308 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
Last week, our Skyport webinar on “How to secure your Active Directory” (https://www.experts-exchange.com/videos/5810/Webinar-Is-Your-Active-Directory-as-Secure-as-You-Think.html?cid=Gene_Skyport) provided 218 attendees with a step-by-step guide for…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

696 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