Thanks & Regards
Kasimurugan (SCJP1.4, SCBCD1.3), Preparing SCWCD1.4
Originally posted by KasiMurugan Ramasamy:
What will happen when a application use case 1(assume 1000 singleton objects), run on a JVM?
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
One of our programmers explains me 'look at google. they do everything simple, the more simple it is the better'. I gave him to write a class. What he wrote instead of one class with 5 lines of code - Factory interface, abstract factory, concrete factory, then the class interface and class implementation (with those 5 lines of code).
Great! The man is reading books how to do things better, sees how google does things, attending university (I think MD), explains how to do things simple... and here you see what he doesI just can't find right words...
Originally posted by Vladas Razas:
And being able to access it globaly is a plus!
The singleton will save you from passing same parameters down the call hierarchy over and over again.
In example you have code that deals with some DBManager. Of course you can have every method (or constructor) to accept one and then all methods it calls also will have one and so on and so forth. Is it flexible ? Yes. But still you will have one DBManager for whole application. So it is unecessary effort and it will not contribute to code readability by not using the singleton.
And again about performance. Don't tune it before you really need to and you know where to.
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
There are other solutions to that problem at lower costs than that of the Singleton pattern.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
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
Originally posted by Vladas Razas:
But singleton is the most simple of them all! That's the beauty of it. All depends on requirements of course.
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
pass around context objects (basically as containers)
*a lot* of code directly accesses it (that's what the global access point is good for, isn't it)
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Stan James:
I did that in my Wiki, but I have to say I felt dirty about it. It seemed to be some admission that I didn't really know what object was going to need what parameters in the future. Do you know if it's consider A Good Thing or not?
It seems you can get around this by saying the global access point (static method) is a creator method that can return any implementation of some interface and just happens to create only one instance at a time. Or maybe that's not Singleton any more? From the outside it would be hard to tell if it used Singleton or Just Create One internally.
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
The point is that requirements change. Every successful system needs to be maintained and extended for years, if not decades. You don't know what requirements will emerge during that time. That's why it's important to manage the dependencies of the code to keep it flexible.
Originally posted by Vladas Razas:
That's an investment!
I think what you suggest is a upfront system design. That is one has to think through all design issues that may change and do it very flexible.
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
Originally posted by Vladas Razas:
However with rapidly changing systems there no doubt will be problems even with most flexible designs. And this investing thing is like, setting things in stone: "this can change and this not".
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
I'm not sure I understand what you are getting at here. Are you suggesting to simply not access the global access point globally, or something else?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Stan James:
I was suggesting establishing the actual implementation class for the singleton through configuration or injection.
But I'm not sure where this turns into Just Create One instead.
Under benefits GoF says things like "The singleton class may be subclassed and it's easy to configure an application with an instance of this extended class. You can configure the application with an instance of the class you need at run-time." Under implementation they have another page and a half about subclassing, registries, etc. These give you permission to solve your unit testing issues, no?
BTW: That "art of design" post really nailed it.![]()
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
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
The City calls upon her steadfast protectors. Now for a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
|