I am speaking especially in regards to using a static variable to accomplish this. Consider the following object in Java:
public class MyObject{
private static ArrayList<String> ID_List = new List<String>();
private String ID_Number;
public MyObject(){
/* Assign a random number to ID_Number
* And ensure that this is a unique number
* not found in ID_List. Then add it to ID_List. */
}
/* Other methods and such */
}
To some degree, this is to ensure that each object made has a unique and distinguishing attribute that is easily accessible and readable. However, I am not sure if this kind of odd coupling between all objects of the same type is good practice.
Since it's making me uncomfortable I'm inclined to think that this isn't a good idea. What is the right way of thinking about this in an OOP manner?