The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
roshan jose wrote:Suppose you are doing a project on entering the employee details into the database..
You have to enter a list of 100 employees...that means you have to create 100 objects using a loop or whatever logic is possible..
Instead you can use Single Ton concept to create only one object and use it to enter the list of 100 employees...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
roshan jose wrote:
So the resource person told us that this concept can be used to create static objects and so you dont have to waste memory space by creating many objects.
by just creating one static object you can enter all the employee details as i have said in my above post
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Maneesh Godbole wrote:In general, a singleton is used for shared resources.
Imagine a scenario where you got lots of classes, who are trying to piggy back on the desktop configuration settings. You know stuff like font and colors and size.
Since the desktop is a common factor, it would be a good design to have a common class which would give you access to all these attributes.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Maneesh Godbole wrote:Ok.
My bad. I did not consider the multiple desktop scenario.
How about a properties manager? Common properties being shared across classes?
Or DBManager where you want one SPOC for all DB related transactions?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Maneesh Godbole wrote:But I do not understand what is going to guarantee the existence of only one instance?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus