I have a very simple hierarchy laid out here.
Base class:
========
class A{
protected ObjectX m_data;
public Object getAttribute(
String name)
{
if(m_data!=null){.......}
}
}
Inheriting classes:
============
public class B extends A {
protected B(ObjectX dataValues)
{
m_data = dataValues;
}
public String getName()
{
if(m_data==null){RefreshData();}
String name=m_data.getAttribute("NAME");
return name;
}
public boolean RefreshData()
{ ....;
.....;
m_data=xxx;
}
}
public class C extends A {
protected C(ObjectX dataValues)
{
m_data = dataValues;
}
public String getAddress(){
if(m_data==null){RefreshData();}
String address=m_data.getAttribute("ADDRESS");
return address;
}
public boolean RefreshData(){
. ...;
.....;
m_data=xxx;
}
}
Important points:
1.A singular instance of B and C are stored in a static hashmap against their respective keys.
So at any instance,we would have multiple clients accessing the same reference of B(and C),and therefore potentially m_data too.
2.The algorithm to refresh m_data is different for inheriting classes B and C - so ' RefreshData()' cannot be promoted to base.
Please suggest the most apt synchronization technique for m_data.