LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Type Definition or Class

Solved!
Go to solution

What is better, using a type definition or a class to define a collection of data elements? Can you share interesting use cases for one over the other? Type defs are simple and dumb, while classes could allow various types of formatting to be applied when getting or setting data.

 

Other thoughts?

0 Kudos
Message 1 of 8
(2,710 Views)

@CanadaGuy wrote:

What is better, using a type definition or a class to define a collection of data elements? Can you share interesting use cases for one over the other? Type defs are simple and dumb, while classes could allow various types of formatting to be applied when getting or setting data.

 

Other thoughts?


These concepts are not either or not better worse.

 

A class may contain a  type defined data element.  A type def might include a class.

 

Give us an example of what you have.  With the data structure in question and in context of where you might use it.   I guarantee you there will be vigorous proponents of both parties 


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 8
(2,686 Views)

A type def is nothing but a definition of the data type.  A class is a set of private data and methods to act on that private data.  If you go into the NXG paradigm, they are actually the same thing, you just choose what level of "classiness" (couldn't think of a better term) the gvi will be.

 

So, it really depends on exactly what you are trying to do with the data.  I use both very regularly.


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
0 Kudos
Message 3 of 8
(2,655 Views)

@crossrulz wrote:

A type def is nothing but a definition of the data type.  A class is a set of private data and methods to act on that private data.  If you go into the NXG paradigm, they are actually the same thing, you just choose what level of "classiness" (couldn't think of a better term) the gvi will be.

 

So, it really depends on exactly what you are trying to do with the data.  I use both very regularly.


I too use both regularly, but I can't say I use them consistently. I suppose what prompts this question is the available functionality to right click on a type def to convert it to a class. It sort of seemed like there is the encouragement to use classes instead of type defs, but maybe I interpreted incorrectly...or I was jumping ahead to the NXG paradigm without knowing it.

0 Kudos
Message 4 of 8
(2,652 Views)
Solution
Accepted by topic author CanadaGuy

Let's reduce this a little more and speak specifically about clusters and access to data in it.  Now the question breaks down to if you want the user of your functions/API to have direct access to all of the values in that cluster.  As I am developing APIs, I am increasingly finding that the user does not, and should not, care about all of the data I am storing in the state.  Therefore, I am using classes more and more to maintain a state.

 

For example, I have a library for communicating with a power supply over an Ethernet connection.  Do I really want the user to be able to randomly change that connection reference?  Absolutely not.  Bad things are likely to happen.  Therefore, I hide details of the library by using a class.  I then also get the benefit of Dynamic Dispatch to further expand capabilities.


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
0 Kudos
Message 5 of 8
(2,645 Views)

I'm a one man team when it comes to programming, so I'm not often keeping other programmers in mind. Now that I am revisiting a lot of code, maybe doing some rewrites, your use case sounds like a pretty good approach and would probably help me when reviewing old code down the road.

0 Kudos
Message 6 of 8
(2,643 Views)

@CanadaGuy wrote:

so I'm not often keeping other programmers in mind.


That is the wrong attitude.  Because you will be that other programmer when you try to reuse a library 6 months from now.  Thinking in terms of APIs has helped my code base immensely.


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 7 of 8
(2,636 Views)

@crossrulz wrote:

@CanadaGuy wrote:

so I'm not often keeping other programmers in mind.


That is the wrong attitude.  Because you will be that other programmer when you try to reuse a library 6 months from now.  Thinking in terms of APIs has helped my code base immensely.


I entirely agree. My todo list for the summer contains "improve LabVIEW skills" 🙂

0 Kudos
Message 8 of 8
(2,633 Views)