Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-23-2008, 08:02 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 255
fishtoprecords is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-23-2008, 08:33 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-23-2008, 06:40 PM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 255
fishtoprecords is on a distinguished road
Quote:
Originally Posted by Eranga View Post
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-24-2008, 04:57 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-24-2008, 06:25 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-24-2008, 06:30 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 255
fishtoprecords is on a distinguished road
Quote:
Originally Posted by Zosden View Post
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.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-24-2008, 06:56 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 06-24-2008, 07:03 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 255
fishtoprecords is on a distinguished road
Quote:
Originally Posted by Eranga
Amazing. If all added in the main method,
I think you may have missed the sarcasm alert.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 06-24-2008, 08:00 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 06-25-2008, 07:21 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 06-25-2008, 07:47 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 07-06-2008, 04:38 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 255
fishtoprecords is on a distinguished road
Here is a view on this topic.
Steve Yeggie
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
a really stupid question SwinGirl NetBeans 10 06-25-2008 10:06 PM
Whether to make Bean Singleton or non Singleton (prototype) Java Tip Java Tips 0 03-29-2008 01:41 PM
Quick Stupid Question bluekswing New To Java 7 01-08-2008 07:35 PM
Whether to make Bean Singleton or non Singleton (prototype) JavaBean Java Tips 0 09-26-2007 09:32 PM
singleton pattern Peter Advanced Java 1 07-09-2007 05:45 AM


All times are GMT +3. The time now is 05:16 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org