|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

06-23-2008, 08:02 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Posts: 255
|
|
|
Singleton considered stupid, Java and complexity
In another thread, I pointed out that the Gang of Four Patterns book has encouraged thousands if not millions of programmers to use the Singleton pattern in Java applications.
This is bad for many reasons. Google for "singleton considered stupid" for a starting set.
A bigger problem, IMHO, is that it encourages non-OO design, and that is way bad.
Since Java is an OO language, how come so many applications are written with little or no thought to the OO style and guidelines?
|
|

06-23-2008, 08:33 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
|
|
|
Even I think that singleton is bad in practice. But it is on my knowledge on it. But I know few people, including few of my friends, heavily used singleton and do there works perfectly.
But what the bad thing there I can see is all about OO. Actually most of the code(Java classes) violate OO concepts massively. I don't think it's good practice. Any OO language should follows OO concepts as much as possible. I like to move with it.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

06-23-2008, 06:40 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Posts: 255
|
|
Originally Posted by Eranga
heavily used singleton and do there works perfectly.
It works, assuming you use the known tools to avoid double check lock bugs.
But a singleton is just global data. It breaks, fundamentally, the concept of encapsulation.
It makes testing with JUnit much harder. And testing with JUnit (or something else) is critical to professional software.
It increases coupling.
And nearly 99% of the time, its just not needed. When you have problems, well documented problems, why use it. Kind of like juggling running chain saws. Sure, some folks can do it, but its a really bad idea.
|
|

06-24-2008, 04:57 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
|
|
I agreed with you. And I don't want to use it anywhere in my applications too. 
I really like to work with Encapsulations. Up to now I have changed the functionality of my code thousand times. If I've not followed OO concepts in good way, in big trouble at all.
Because of that in the past I start to work on OO concepts in more depth, decide to avoid singleton as much as possible.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

06-24-2008, 06:25 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
|
I put all my code into the main method that way its all in one place making it easier to read. If you dont sense the sarcasm stop reading. Any ways oo is good for most projects but somethings a programmer doesn't have time to figure a way around the problem.
__________________
My IP address is 127.0.0.1
|
|

06-24-2008, 06:30 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Posts: 255
|
|
Originally Posted by Zosden
oo is good for most projects but somethings a programmer doesn't have time to figure a way around the problem.
OO is wonderful for some problems, not so good for others.
But if the programmer isn't smart enough to figure out a solution in the time allowed, maybe they should practice saying "you want fries with that?"
Or find a job with a smarter PHB.
The key point is that the Gang of Four practice is out dated and is bad, OO or not-OO.
|
|

06-24-2008, 06:56 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
|
|
|
Amazing. If all added in the main method, how terrible to read the code. I mean all in one place always make a trouble. Just think, how nice if we separate similar functionality in different locations. I'm just say this on common sense, not in OO concepts.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

06-24-2008, 07:03 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Posts: 255
|
|
Originally Posted by Eranga
Amazing. If all added in the main method,
I think you may have missed the sarcasm alert.
|
|

06-24-2008, 08:00 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
|
|
|
No I'm not, I just say what I feel on that post. Because I know lots of people use in that way. I found more people here in our forum too. Some members put there code here, with only one method(that is the main method) and it contains around 100 of lines.
I never look at that code, because it's a mess for me. Really difficult to read the post until the end.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

06-25-2008, 07:21 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
|
LOL most of those post are from people who have just started. Besides who would put anything in one method when its much more fun to put each line in separate methods.
__________________
My IP address is 127.0.0.1
|
|

06-25-2008, 07:47 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
|
|
Because everyone has there own passion of coding. As you said people used 100 of methods in a single class, with few line of code. Some are in other way around. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

07-06-2008, 04:38 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Posts: 255
|
|
Here is a view on this topic.
Steve Yeggie
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|