Hi all, I am searching solution for a problem and seek help from you... I want to have control on the maximum number of instances, that I could have ,on a particular class. How could I implement it ? One possible solution that I was suggested was to use the Singleton class but It allows only on object of a class. I need a specific number of objects.
Please help me out of this. Thanks and Regards Amit
By Singlton method, u can create multiple instances also.
Check this out
Class FixedInstanceExample
{
private instanceAllowed= 5 ;
//fix the number of instance to 5
private Vector fixedInstance = new Vector();
private FixedInstanceExample()
{
}
publicstatic FixedInstanceExample getInstace()
{
if (fixedInstance.size()<instanceAllowed)
{
FixedInstanceExample ex = new FixedInstanceExample();
fixedInstance.add(ex);
return (ex);
}
else
{
//return any of the instance
}
}
}
//NOTE THAT THE CLASS IS JUST AN IDEA
// U CAN IMPLEMENT UR FINALIZER METHOD TO REMOVE INSTANCES FROM VECTOR
[java]
By Singlton method, u can create multiple instances also.
Check this out
Class FixedInstanceExample
{
private instanceAllowed= 5 ;
//fix the number of instance to 5
private Vector fixedInstance = new Vector();
private FixedInstanceExample()
{
}
publicstatic FixedInstanceExample getInstace()
{
if (fixedInstance.size()<instanceAllowed)
{
FixedInstanceExample ex = new FixedInstanceExample();
fixedInstance.add(ex);
return (ex);
}
else
{
//return any of the instance
}
}
}
//NOTE THAT THE CLASS IS JUST AN IDEA
// U CAN IMPLEMENT UR FINALIZER METHOD TO REMOVE INSTANCES FROM VECTOR