It is currently Thu Mar 28, 2024 5:29 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 

Is Harry too tired to make words happen?
Yes No 0%  0%  [ 0 ]
Spoiler for asd:
100%  100%  [ 1 ]
No 0%  0%  [ 0 ]
No 0%  0%  [ 0 ]
Total votes : 1
Author Message
 Post Post subject: Singleton Vs Single Object?
 
Offline
Unstoppable
Unstoppable
Years of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membership

Joined: Sun Nov 15, 2009 8:40 pm
Posts: 1038
Karma: 10
Since a lot of you on here actually program, I want your thoughts/opinions or cold hard facts telling me where I am wrong. This may not specifically apply to the C family, but I don't see why it shouldn't.


So I recently learned what a Singleton class is. Lets say you have an object, that you only ever have one of. Be it a Player class for a game, or a JsonHandler for a program.
So lets say that your ONLY ever going to use 1 of these objects that you make, should you indefinitely treat it as a singleton, rather than passing it through many functions and to child objects? I'm probably sprouting <HERP TO MY DERP> right now, but I just find that it's a lot nicer to use ClassName.getProperty, instead of having a static decleration in main and using, Main.myClassNameObject.getProperty.
It's also faster than doing "new JsonManager.someFunction();" every time you want something.

Especially, when it comes to multi-threaded programs. Since a certain variable could get locked up, while you're trying to access a member of it. I don't know, this could most probably be prevented by thinking about your code before doing it but it's not exactly difficult to turn a regular class into a singleton, and vice versa.

Also, just figured out that you can use the forums BB codes or whatever they are called, in a poll.


Wed Jun 27, 2012 3:43 am 
 Profile E-mail  
 
 Post Post subject: Re: Singleton Vs Single Object?
 
Offline
Godlike Poster
Godlike Poster
Years of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membership
User avatar

Joined: Sun Oct 16, 2005 9:42 am
Posts: 8798
Karma: 17

Location: Imagine in your mind a posh country club
Steam Login Name: azcn2503
It's often better to just keep things simple. It's always worth asking yourself, when making a program (of any sort, be it web or compiled or whatever) - do I really need an advanced class based class.property/object.property style function, or should I just resort to doing something that works in the most simple way. If it doesn't need to be placed within a larger organisational object of some sort, and if it is not hurting to keep it standalone/global/whatever, you should just do that.

Although I am sure there are many arguments for and against it. Preach practise all you want, etc. but at the end of the day, does it work?

:)

_________________
Follow your heart and live the dream <3


Wed Oct 31, 2012 5:01 pm 
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Karma functions powered by Karma MOD © 2007, 2009 m157y