Jump to content

Singleton Parent and children classes


Recommended Posts

Hi everyone! I am new in the comunity, so this is my first post!

I would like to ask you about singletone pattern used with inherintace.

I implemented a framework based on pluggins, in which there is a GeneralPluggin with common attributes and five child pluggins that adds some funcionality and its own attributes. I realized that these pluggins coorespond to the singleton pattern so I used the Goop tool to create them in this way. Due to they inherit from a not singletone class (and also a Labview normal class, not goop class) to use the parent vis I made public the "Get_Instance" vi despite I knew it was wrong, in order to give the generic pluggin vis the input value that it needs.

The problem with it is that the program, sometimes, creates some instances with the same reference, but ones are filled with the correct data and the other are empty. To solve this issue I'm trying to redo the Genericpluggin class in the singletone pattern and inherit from it again.

But I have some questions, how can the child classes access to the parent atributes ?

And how can they know which class is the proper child class which is calling the paret funcionality if there is not " class reference In " in the vi, as it is singleton.... I mean without wiring them anything to specify the type...

For instance, I have in the parent class an atribute called name, and to different pluging which inherit from this one, one is called acquisition, and the other one tracking, If I drag the parent vi "GetName" which does not recieve an input specifying the class type and inside this Vi it calls to the parent "GetInstance" to have access to its attributes how LabView know if I asking for "Tracking" or for "Acquisition" atributte??

Or in a normal class you wire the child class calling a parent vi method, and as you wire the class in, it knows which child function should call but in this case... I'm a bit confused!!!

I saw in other thread in this forum a possible solution, inherit from a normal class and make the children singleton should work. I could try to make the GenericPlugin with goop (after it is done by LabView normal class) which I think it will work better. But I have the same doubts... How can I call the children instances? Implementing a "Must Override" method "GetInstance" and calling this method inside the funcional father Vi...?

THANKS IN ADVANCE!!!!

Link to comment

Here is an example using inheritance with Singelton made with GOOP Development Suite's GOOP4 DVR classes.

You need some kind of reference-base OO design to get Singleton working.

But make sure you only use singleton when you know that you only will have one object of that type.

Singleton.zip

Cheers,

Mike

Link to comment

Thanks a lot, I didn't know how to access the parent atributes.

I have a couple more questions... :)

I don't know If i am wrong, but it seems like you cannot inherit methods from the parent class, for explame in the child in the code you send me it is reimplemented the vi GetLog, when is basiclly the same vi tha is already done in the father. I guess it is caused by the lack of input objects to the singletone vis.

So in my case, create a singletone generic vi may not be the proper arquitecture, because i am avoiding recode some vi's. Or I'm thinking, for

instance, for the LoadPanel is a vi that just take the main Vi and load it into a subpanel, instead call the parent loadpanel vi, I should call a specific LoadPanel.vi but inside it I can call the parent one in order to reuse code. What do you think?

Other aproach would be make the genericPluggin GOOP Single Class and use the parent vis. As I said these vis would need a input with the object whici is calling the vi (if there is another way, please let me know). To mange that we could wire a "class constant" when we use the parent vi's, to indicate which child we want to call, and inside the child vi get the proper Instance, and the neccesary atributes. To avoid calling the GetInstance method out of the singletone class as I did. for instance in the LoadPanel.vi in the main.vi in the "Acquisition state" there will be a call to the LoadParent.vi with an "acquisitionPLugginClass" constant like input, inside "LoadPanel" it will use this constant to know which child is and which methods has to call among the children ones. But sounds me like a "trick"... I'm not sure which one to chose...

Which aproach do you thin is the best one?

Thanks for you help :yes:

Link to comment

Hi it looks like your getting the hang of OO.

You are right you can't use dynamic dispatch when it comes to Singleton Methods.

You could use a Singleton Class for handling all your plug-ins. e.g. Load, Start and Stop them

But every plug-in has to be a By Value or By Reference class.

For plug-in architecture you can find many threads on this here at Lava and NI Forums.

Try: http://lmgtfy.com/?q=Class+Plug+in+architecture+in+LabVIEW

Link to comment

Yeah! I've seen the documents and examples. Actually it was the one IU pluggin explained in decibel (https://decibel.ni.com/content/groups/large-labview-application-development/blog/2011/05/08/an-approach-to-managing-plugins-in-a-labview-application) the one which I used to learn how to handle pluggins. The problem became when I tryed to melt it with the singletone pattern in the pluggins.

Thanks for all, I will let you know my next steps :)

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.