N-ton class(How to create an n-ton class) example plz.........

I need to create 5 objects for a class. Means should not be able to create number of objects>5 or number of objects<5 for that class. How to create a class with finite number of objects........
[206 byte] By [jaseemkhana] at [2007-11-26 12:24:17]
# 1
And you can't deduce what you have to do from looking at a Singleton example? No good start, don't you think?Have a static List or array, initialized with five instances. Done.
CeciNEstPasUnProgrammeura at 2007-7-7 15:25:21 > top of Java-index,Java Essentials,Java Programming...
# 2

> And you can't deduce what you have to do from looking

> at a Singleton example? No good start, don't you

> think?

>

> Have a static List or array, initialized with five

> instances. Done.

If List (or Set), also make it [url=http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#unmodifiableList(java.util.List)]unmodifiable[/url].

mlka at 2007-7-7 15:25:21 > top of Java-index,Java Essentials,Java Programming...
# 3

> If List (or Set), also make it

> [url=http://java.sun.com/j2se/1.4.2/docs/api/java/util

> /Collections.html#unmodifiableList(java.util.List)]unm

> odifiable[/url].

Not necessarily necessary. :) As long as the class doesn't modify it and he never provides a reference to that list to anyone else, it should be okay.

CeciNEstPasUnProgrammeura at 2007-7-7 15:25:21 > top of Java-index,Java Essentials,Java Programming...
# 4
Just curious: why do you want to have 5 instances right from the start? What kind of application is it for?
Peetzorea at 2007-7-7 15:25:21 > top of Java-index,Java Essentials,Java Programming...
# 5
> Not necessarily necessary. Nor is making the list final. As long as your class don't modify the reference. :)
mlka at 2007-7-7 15:25:21 > top of Java-index,Java Essentials,Java Programming...
# 6
> > Not necessarily necessary. > > Nor is making the list final. As long as your class> don't modify the reference. :)I didn't say that the list should be final. Of course, everything that can be final should be final IMO.
CeciNEstPasUnProgrammeura at 2007-7-7 15:25:21 > top of Java-index,Java Essentials,Java Programming...
# 7
> Just curious: why do you want to have 5 instances> right from the start? What kind of application is it> for?Because thats what his teacher specified!
ScarletPimpernela at 2007-7-7 15:25:21 > top of Java-index,Java Essentials,Java Programming...
# 8
> Just curious: why do you want to have 5 instances> right from the start? What kind of application is it> for?Maybe connection pooling or something. Or homework.
CeciNEstPasUnProgrammeura at 2007-7-7 15:25:21 > top of Java-index,Java Essentials,Java Programming...
# 9
> I didn't say that the list should be final. Of> course, everything that can be final should be final> IMO.Mm, so you did not. I thought you did .
mlka at 2007-7-7 15:25:21 > top of Java-index,Java Essentials,Java Programming...