I have base class DataProcessor
. It is base class for calculators of position in some coordinate system. So, for example, it can have descendants like: SphericDataProcessor
, CartesianDataProcessor
. There is base class CookedDataCatalogue
, which is base class for containers of some objects' positions. So every DataProcessor
should be able put it's data to every CookedDataCatalogue
. I can imagine something like this:
class CookedDataCatalogue
{
virtual void Transform(DataProcessor* dp) = 0;
virtual void PutData(???) = 0;
}
class CookedDataCatalogue1 : public CookedDataCatalogue
{
void Transform(DataProcessor* dp) override
{
dp->TransformTo(this);
}
}
class CookedDataCatalogue2 : public CookedDataCatalogue
{
...
}
class CookedDataCatalogue3 ...
class DataProcessor
{
virtual void Process() = 0;
virtual void TransformTo(CookedDataCatalogue1* c) = 0;
virtual void TransformTo(CookedDataCatalogue2* c) = 0;
virtual void TransformTo(CookedDataCatalogue3* c) = 0;
}
But I don't like it. First of all void Transform(DataProcessor*) migrates from base class to all children. Second, if I build it as library, other user can not add his own CookedDataUserCatalogue
, because he can't add another void TransformTo(CookedDataUserCatalogue)
. Third, I don't know how to write function PutData()
, because every Catalogue uses his own data to contain. Should it be templated?
What is a solution? Is there any programming pattern, that I missed?
Aucun commentaire:
Enregistrer un commentaire