Before marking duplicate please read:
I did read the following article and found the potential 'solutions' not to be what I was looking for as most of them address using an equals() method.
Classes sharing the same super class instance
What I am looking to do is to have multiple static accessible subclass instances that can share a single parent class instance so that changes to the parent instance will be reflected. I am open to a variety of solutions however I am trying to minimize the number of object references and must store and call these instances in a static manner.
Hopefully the following code will explain in more detail what I am trying to achieve.
// ParentClass
public class School {
private static final HashMap<String,School> pmapping = new HashMap<>();
private final String pname;
private int pvalue;
private School( String name, int value) {
pname = name;
pvalue = value;
pmapping.put(name,this);
}
public static School build( String name, int value) {
return this( name, value);
public static School instance( String name) {
// Yes there will be exception handling in the final version
return mapping.get(name);
public String name() {
return pname;
}
public void setValue( int value) {
pvalue = value;
}
public void getValue( ) {
return pvalue;
}
}
// ChildClass
public class Subschool extends School {
private static final HashMap<String,Subschool> cmapping = new HashMap<>();
private final String cname;
private Subschool( School school, String name) {
// what I would like to happen
super = school;
cname = name;
cmapping.put( cname, this);
}
public static School build( String school, String name) {
School s = School.instance(school);
return this( s, name);
public static School instance( String name) {
// Yes there will be exception handling in the final version
return cmapping.get(name);
public String name() {
return cname;
}
}
// TestClass
public class Test {
public static main(String[] args){
// What I need to occur
School illusion = School.build( "Illusion", 1);
Subschool figment = Subschool.build( "Illusion", "Figment");
Subschool shadow = Subschool.build( "Illusion", "Shadow");
illusion.setValue( 3);
if( figment.getValue() == 3)
System.out.println( "Check 1 Succeed");
if( figment.getValue() == shadow.getValue() )
System.out.println( "Check 2 Succeed");
}
}