durnek60 Posted August 14, 2011 Report Share Posted August 14, 2011 Hi! What are the mayor differences between DVR and singleton template in GOOP4? Singleton: Only one object instance in memory Not wire required Simple DVR: Wire Requeid Multiple instances can be in memory. anyway, could you tell me when should I use Simple DVR and Singleton? Thanks! Quote Link to comment
Jon Kokott Posted August 22, 2011 Report Share Posted August 22, 2011 Personally, I do not care for singletons anywhere in my code. To me, not having a wire is a disadvantage. This is because establishing the scope of a given object becomes difficult. I've debugged enough code from others and figuring out where all the FG (singletons) are is PAINFUL when there are 30 different ones called in 1000 places. Singletons have awful connector panes in many cases (using a variant or class input output can fix this.) Lastly, thinking you'll only need one of these objects WILL bite you one day, its only a matter of time, and it is (usually) nontrivial to convert it to a by reference implementation. So here is my opinion of when it is appropriate to use a FG/singleton: 1. Configuration information. This applies to any "Variable" that you set ONE TIME and then read throughout the application. If you want to change that info, don't use a singleton. 2. I don't have anything else, People do use them for other things such as a "global Stop" which I'm willing to deal with, but I'd rather use event based stopping. When to use a DVR: If you deem it appropriate to use a by ref pattern, DVR is prefered to SEQ/CBR nodes because: It runs the fastest it has a clear lock/unlock scope within a method. My 2 cents. At the end of the day you should probably pick the implementation that works best for you and your team in terms of understanding and maintainability. If noone knows what the heck a by reference pattern is but FGs "click" for them, either spend some time learning about different ways to program or do what works. There are lots of people who have used FGs in large applications which have been maintained over a long period of time. I simply believe that they are obsolete today. ~Jon ~Jon Quote Link to comment
Daklu Posted August 22, 2011 Report Share Posted August 22, 2011 I agree with everything Jon said, except the part about it being appropriate to use singletons for immutable objects. True, immutable singletons don't have the issue of race conditions mutable singletons have, but it's still hard to determine the scope of where it is used (because of the absence of wires) and it encourages a messy dependency tree (because it's so easy to retrieve the data from anywhere.) Personally I don't use singletons for anything and I very rarely use reference data of any kind. When I do use reference data I try to limit it to a single block diagram so it is easy to verify correctness. In my opinion, there are a couple times when reference-based data is appropriate: -It is the best technical decision given the constraints of the project. (i.e. Memory limitations, etc.) -It is the best business decision and all stakeholders understand the cost/benefit tradeoff and long-term impact of the decision. If you dig into the *real* reason people use reference data, usually it amounts to "it's easier to implement" or "I don't know how to solve this problem without using reference data." Quote Link to comment
Jon Kokott Posted August 22, 2011 Report Share Posted August 22, 2011 If you dig into the *real* reason people use reference data, usually it amounts to "it's easier to implement" or "I don't know how to solve this problem without using reference data." Considering how well developed by reference programming is (in general computer science as well as labview) I wouldn't say that at all. Atomic actions on a piece of data can be done in more than one way, and there are performance/maintainability tradeoffs when choosing between say an Actor framework and something strictly by reference. If anything you should know both and understand the design constraints you have imposed on yourself before deciding that one or the other is the best. Quote Link to comment
spdavids Posted September 7, 2011 Report Share Posted September 7, 2011 Hi Jon, In GOOP4 the singleton template is just a DVR class which restricts the creation of an object to only one instance. For the singleton template you get a protected method(GetInstance) to create/access your object. If you go for the simple DVR class you have a public create method to create your objects. As far as when to use the two approaches I guess you have already answered it your self a bit. When you only need one instance of a class and global access to it. A few occassions when you could use a singleton is for an error class, or a log class or some kind of communication class. BR Stefan Quote Link to comment
MikaelH Posted September 7, 2011 Report Share Posted September 7, 2011 I use singletons in a system when I want to enforce to only use one Object of a class, and I can see many cases of that. So e.g. you would only create one object of your class LHC, since we can only afford to build one. Cheers, Mike 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.