LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to access a class for read/write from multiple other classes?

Solved!
Go to solution
I need runtime to be preserved on a class that gets read to and written to by other classes. They share no common ancestry. The read/writes will be synchronous so there's no race conditions to worry about. My idea is to just have the class be private data of all the classes that need to access it and do a "handoff" between classes, eg bundling and unbundling it into the classes that need it. This seems messy though. Any ideas?
0 Kudos
Message 1 of 7
(3,359 Views)
One idea is to use a functional global, but I don't think Labview classes would like that.
0 Kudos
Message 2 of 7
(3,356 Views)

AE's can work but can also put a restriction on how re-usable your code will be.

 

I think you are looking for a Singleton Design pattern.

 

Search this site, there used tobe links and examples.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 7
(3,342 Views)
Solution
Accepted by topic author ijustlovemath

I use a Data Value Reference in this situation.  You just make a DVR that contains your shared class and then pass that DVR into all of your other objects at their initialization.  Since everybody who needs to alter the data has a reference to the data, everybody can change it inside of their private methods via an In Place Element Structure.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 7
(3,317 Views)

You can install G# and use referrence based classes, which'd make it simple enough. 🙂

They basically work like Crossrulz suggest.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 7
(3,303 Views)
Is G# supported in the runtime engine?
0 Kudos
Message 6 of 7
(3,299 Views)

Yes.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 7
(3,232 Views)