Maite Posted June 1, 2012 Report Share Posted June 1, 2012 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!!!! Quote Link to comment
Maite Posted June 4, 2012 Author Report Share Posted June 4, 2012 Can anyone explain to me how singleton inheritance works? I mean if there is one parent and two childrend all singletone classes, how can one of the child access the parent atributes ?? thanks a lot! Quote Link to comment
MikaelH Posted June 4, 2012 Report Share Posted June 4, 2012 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 Quote Link to comment
Maite Posted June 4, 2012 Author Report Share Posted June 4, 2012 THANKS! I will have a look to it rigth now! Quote Link to comment
Maite Posted June 4, 2012 Author Report Share Posted June 4, 2012 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 Quote Link to comment
MikaelH Posted June 5, 2012 Report Share Posted June 5, 2012 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 Quote Link to comment
Maite Posted June 5, 2012 Author Report Share Posted June 5, 2012 Thanks again! Quote Link to comment
Maite Posted June 5, 2012 Author Report Share Posted June 5, 2012 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 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.