Jump to content

GOOP4 Simple DVR vs. Singleton Template


Recommended Posts

Hi!

What are the mayor differences between DVR and singleton template in GOOP4?

Singleton:

  1. Only one object instance in memory
  2. Not wire required :)

Simple DVR:

  1. Wire Requeid
  2. Multiple instances can be in memory.

anyway, could you tell me when should I use Simple DVR and Singleton?

Thanks!

Link to comment

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

Link to comment

I agree with everything Jon said, except the part about it being appropriate to use singletons for immutable objects. :P

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."

Link to comment

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.

Link to comment
  • 3 weeks later...

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

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.