LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What's the best way to implement an array on OOP?

Hello,

 

In the attached image, I do a database query with one query string. It opens the connection, makes the query, and closes the connection. The output array is scanned for certain conditions later.

 

If I have 10 queries I could simply make an array of queries and make an array of replies. Then I could decompose the output array in a for loop and run my evaluations.

 

In OOP however, I find myself wanting to make each query as an object, to encapsulate it. That is a problem though, because the database resides in a server in another building across town, and the connection to it is slow. So multiple queries take too long.

 

How do I approach this in OOP?

 

database query question.png

0 Kudos
Message 1 of 5
(2,411 Views)

In your class you would have an open method, some query methods, and a close method. Outside of a loop you call the open method. Wire the class to the left side of the loop and make it a shift register. Do your queries in the loop, and after the loop call the close method. You might find that it is faster since you are not opening and closing the connection for each query.

=====================
LabVIEW 2012


0 Kudos
Message 2 of 5
(2,407 Views)

For something like this I would definately consider an architexture simmilar to the Actor framework.

 

You are going to want to only open the connection once as described above, but you want those requests to occur in a different thread than your parsing.  I realize that your parsing time may be negligable but because of your slow connection I would still offload that processing to keep the database busy at all times.

 

Essentially you'll be making a loop which responds to transaction requests and sends results back to the requester as they come in.  

------------------------------------
Jon Kokott
CLA, CLED, CTD, MCP C#
0 Kudos
Message 3 of 5
(2,398 Views)

Or yet another approach...

 

Use "Composition" pattern to say the connection is a part of the query and implement the connection class using the Singlton pattern.

 

The Connection method that crates the connection would only make the connection when an open is invoked and the connection does not alreday exist.

 

So your queries are an array like what seems natural (is that "Cohesion").

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 5
(2,389 Views)

Wow. Lots to think about. First I'd heard of the Actor Framework.

0 Kudos
Message 5 of 5
(2,379 Views)