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
Solved

Classes Question

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AD architecture diagram 5 34
learn programming 8 39
Why use this lambda? 12 35
Group Policy Management - Remove Folder Redirection Entry 1 19
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

856 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