04-12-2012 06:24 AM
Factory Pattern..
I am using factory pattern for its advantage of loading classes into memory when it is called dynamically.
But I am able to see all the classes loaded into memory by looking into LabVIEW Class Hierarchy window and VI Hierarchy window.
Where this not happen. Please suggest solution for this query.
04-12-2012 07:11 AM
If you want to focus on a particular class tree, in the heirarchy window, right click the class you are interested in and select "Show Class Heirarchy"
04-12-2012 07:31 AM
from my understanding the benefit is, that the right function according to the class called is used (e.g. "execute.vi" from the actor framework) - not that the classes are created during runtime.
To call these functions you will probably dynamically create an Object of this class - this is indeed done during runtime - at least to my understanding (Like you have the class "car" and create during runtime objects - a ford and a mercedes. They are created during runtime. Factory pattern means to me, if you also have a class Motorbike that is a descendant from "Motorized transport" or so, and both have of cause inherited the function "drive.vi", then the factory pattern once calls the one corresponding to motorcycle or the one for the cars - during runtime).
Saying this - the class, the prototype for all instances is in memory; but special instances are created during runtime. Anyhow, thats not what the factory pattern is about - at least to my understanding. If I am wrong, please let me know as I am trying to learn that right now...
04-12-2012 11:09 AM
I'll reply but I am no OOPer expert.
THe factory pattern as implemented in LV is just anum driven case structure where each case can have a different instance of a class constant. All of the Class constants exit through the same tunnel that LV cast as the common ancestor class of all of the constants in the case structre.
The exiting wire can be wired to any method available for the common parent class.
So it is a code construct that lets you choose the type of data on the wire.
The Actor Frame work is another fancy term for a generic barckground task.
Actors can be instaciated using using teh Factory Pattern to choose the "flavor" of background task.
Re: All in memory
If the classes are in the project and the project is open then all of the classes are loaded to make sure they are healty.
In an exe that is not always the case as is the situation when the classes are not part of the project or the project is closed.
This image (and the others in that album) show a method I used to find and use compatable classes to create the background task (Active Object).
Active Object (as I understand them) are instances of a Class that function indepenently once created and provided a method to allow other objects to invoke its exposed methods.
Example DAQ_Collector
Child of an I/O class that runs in the background and acepts commands(invoked methods) like "Start", Stop, Exit.
I will now step back to let those who know more correct what I havge posted.
Have fun!
Ben
04-13-2012 12:11 AM
I am using factory pattern for its advantage of loading classes only a single calss into memory when needed.
I saw LabVIEW example on http://files.vishots.com/wp-content/uploads/2011/04/VISV-005-Code.zip as well as a short video of this on http://vishots.com/005-visv-labview-class-factory-pattern/
I opened the project from above example (Note: I haven't still opened Main UI (Dynamic class loading).vi). Now, if I see LabVIEW Class Hierarchy window and VI Hierarchy window I'm able to see all the classes and Sub VI's loaded into memory.
I'm not able to understand this behaviour.
I would appreciate if someone can take a look in to this.
04-13-2012 03:55 AM
I had a look at that project and it shows a development time factory pattern. That is to say, the plug in classes are selected from an enum during development rather than loaded on the fly during run time.
The class heirarchy shows the DMM parent class, and both of the "Emulator" and "Agilent" children classes; and you want to know why they are shown in the heirarchy window if they are meant to be dynamic? They are in memory from being loaded in the project explorer! If you want to hide the classes, you will need to implement a run time factory pattern, where the class loader checks a directory and loads dynamic dispatch from there.
04-13-2012 07:41 AM
@yenknip wrote:
...
That is where I learned how to do it!
Ben