Jump to content

Multiple Instance Initialization


Recommended Posts

Hello All -

I am using LV8.6 I am new to LVOOP and I am stuck in a rut trying to solve the following problem.

Prelim:

Class_A has an instance of Class_X and three instances of Class_B. (Would it be correct to say that Class_A inherits from Class_X and Class_B?)

Class_B has an instance of Class_C. (Again...inherits from Class_C?)

Problem:

1) When I have to "INIT" Class_B from within Class_A:Init how does each instance of Class_B get its own unique parameters?

2) How does Class_B:Init know to initialize Class_B.lvclass different from Class_B.lvclass 2 different from Class_B.lvclass 3?

- For example each instance of Class_B is initialized with a different COM port.

3) Can the input lines (blue arrows below) be used to tell the method which parameters to initialize the calling instance?

Screen shot of block diagram of Class_A:Init:

post-4247-1227047950.jpg?width=400

Thanks for your help.

Link to comment

QUOTE (san26141 @ Nov 18 2008, 02:49 PM)

Nope. Class_A contains some instances of ClassB. Containing is a "... has a ..." relationship, while inheritance is an "... is a ... " relationship. Stick those in a sentence to see which relationship makes sense.

For example, truck is a vehicle, so it inherits the properties of vehicles (has wheels, uses gas, moves on roads). Truck has a gas tank (or two), but that doesn't mean any thing about shared properties. Methods you run on the gas tank (fill it's storage area with gasoline) would not also work on a truck (ok, forget about gas tanker trucks because LV does not support multiple inheritance).

QUOTE (san26141 @ Nov 18 2008, 02:49 PM)

Problem:

1) When I have to "INIT" Class_B from within Class_A:Init how does each instance of Class_B get its own unique parameters?

2) How does Class_B:Init know to initialize Class_B.lvclass different from Class_B.lvclass 2 different from Class_B.lvclass 3?

- For example each instance of Class_B is initialized with a different COM port.

3) Can the input lines (blue arrows below) be used to tell the method which parameters to initialize the calling instance?

LabVIEW OOP is not like many other by-reference OOP implementations. even if you don't call your init function, the existence of your wires on the diagram allocates memory and instantiates a copy of every class. You have 3 classB wires, so you already have 3 different objects. However, they don't contain anything until you fill their private data with the values. Somewhere on your diagram you have to get the COM port values from somewhere (front panel and/or a config file) and pass them into your classB init routines. Actually they don't have to be init routines, they can just be an accessor method to update the COMport element of ClassB.

Usually a LabVOOP Initialize method does not take a copy of the class in, and therefore is an initializer because the new wire out is the first time that object's wire and the data its holding comes into existence. The wires pointed to by your blue arrows could be deleted, since they are probably empty anyway. If they are not empty, you probably are not initializing. Similarly since this is the diagram of ClassA:Init, you don't need to input class A (typically you would put a constant copy of it on your diagram which is all empty, and then bundle in the values from calls to ClassB:init.

hope that helps.

Link to comment

QUOTE (san26141 @ Nov 18 2008, 02:49 PM)

No, what you are showing is not inheritance. You are including Class_X and Class_B as a private data members, which is called aggregation.

QUOTE (san26141 @ Nov 18 2008, 02:49 PM)

1) When I have to "INIT" Class_B from within Class_A:Init how does each instance of Class_B get its own unique parameters?

You can't in your example (assuming the parameters are not already contained in the class data.)

QUOTE (san26141 @ Nov 18 2008, 02:49 PM)

There are two ways:

  1. If you want to assign parameters to the Class_B object in Init.vi you need to create an input to the vi and wire unique inputs to each instance of it.
  2. Store the parameters as private class data, and create accessor method VIs to manipulate the internal parameters. For example, you could have a numeric control named com_port to store the com port number. Then you would create a Set COM Port vi and a Get COM Port vi to write and read the private data. You would use Set COM Port at some point prior to calling Init.
    Then, within Init.vi, you can unbundle the private data and use the com port number associated with that particular object rather than relying on Init.vi input parameters.

QUOTE (san26141 @ Nov 18 2008, 02:49 PM)

3) Can the input lines (blue arrows below) be used to tell the method which parameters to initialize the calling instance?

The "input lines" you are referring to are in fact object wires, and carry all the information pertaining to the object on the wire, including the values of all of that object's private data. So the quick answer is yes, the object wires can indirectly tell Init.vi which parameters to use (although it's probably in a different way than you intended.)

QUOTE (jdunham)

Usually a LabVOOP Initialize method does not take a copy of the class in, and therefore is an initializer because the new wire out is the first time that object's wire and the data its holding comes into existence.

If you want your initialize method to be inheritable it needs to have a class input, otherwise LV doesn't know which class initialize method to call.

(FWIW my initialize methods are reserved for initializing hardware. I use create new methods when I was to control how new objects are formed.)

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.