Solved

Classes Question

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

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
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…
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…

746 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

13 Experts available now in Live!

Get 1:1 Help Now