My colleague has created a class that has itself as a static attribute.
public class GroupProject {
public static GroupProject staticGroupProject;
private String groupId;
public void setGroupId(String id) {
if (groupId != null) {
groupId = id;
}
}
}
public class GroupProjectUtils {
public void startGroupProject() {
GroupProject.staticGroupProject = new GroupProject();
}
public void stopGroupProject() {
GroupProject.staticGroupProject = null;
}
public void setIdentification(String identification) {
GroupProject.staticGroupProject.setGroupId(identification);
}
}
- How to reason about this code in OOP terms?
- Does it actually function like a top-level static class?
- Is doing this generally speaking a good or a bad practice?
EDIT: Thank you for your suggestions. This comment here answers the question well - Java Singleton Design Pattern : Questions.