Results 1 to 12 of 12
- 06-23-2008, 07:02 AM #1
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, 07:33 AM #2
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.
- 06-23-2008, 05:40 PM #3
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, 03:57 AM #4
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.
- 06-24-2008, 05:25 AM #5
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, 05:30 AM #6
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, 05:56 AM #7
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.
- 06-24-2008, 06:03 AM #8Originally Posted by Eranga
- 06-24-2008, 07:00 AM #9
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.
- 06-25-2008, 06:21 AM #10
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, 06:47 AM #11
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. :)
- 07-06-2008, 03:38 AM #12
- By SwinGirl in forum NetBeansReplies: 10Last Post: 06-25-2008, 09:06 PM
- By Java Tip in forum Java TipReplies: 0Last Post: 03-29-2008, 01:41 PM
- By bluekswing in forum New To JavaReplies: 7Last Post: 01-08-2008, 07:35 PM
- By JavaBean in forum Java TipReplies: 0Last Post: 09-26-2007, 08:32 PM
- By Peter in forum Advanced JavaReplies: 1Last Post: 07-09-2007, 04:45 AM