Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

What is diffrence between Singleton and a Nested class

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is diffrence between Singleton and a Nested class?
I think nested class is same like singleton except that is inside a class.
please help.
 
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi:
please refer to:
Introduction to Inner Classes;
Java vs. Delphi;
Code Style Guide.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
singleton is best understood as a pattern that solves a design problem : how to ensure that only one instance of a class exists. the usual strategy to make this happen is:
1. stop clients making instances of the class by declaring a private constructor.
2. make the class contain a single instance of itself as a member.
3. provide a static method for returning that single instance. very crudely:

public class MySingleton{
private MySingleton(){}
private MySingleton singleton = null;
public static MySingleton getInstance(){
if (singleton == null){
singleton = new MySingleton();
}
return singleton;
}
}
now, inner classes are (generally) a useful method of encapsulating class-only functionality inside fully fledged objects - they solve the problem of unwieldy implementations and excessively sprawling class heirarchies. so they solve an implementation problem , not a design problem. maybe you have some particular issue that lead to the question that you could share?
peter
 
Ashish Kothari
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,peter,though,I know the exact details of both but I was unable to explain it somebody who asked .
One more question I would like (that is diffrent from this one),I want to swap two strings thru a method like swap(String str,String str1).
but passing thru reference does not work,do you know How can I swap values of String thru method.
Is this possible as strings are immutable.
 
Every time you till, you lose 30% of your organic matter. But this tiny ad is durable:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic