I don't know if I'm utterly wrong here, but I'd like to create an interface class that's implemented by all objects containing data. I'd like all data to be accessible through said interface (if you have the correct object too).
Someone might write
class Data
{
public:
// p_attrId attribute identifier, unique for a specific attribute Rectangle::eWidth or Human::eHeight (etc.)
// p_in value to set
// returns true if set false if not. human->set(Rectangle::eWidth); would return false, unlesss human inherits rectangle
virtual bool set(int p_attrId, QVariant const & p_in) = 0;
virtual bool get(int p_attrId, QVariant & p_out) const = 0;
};
And be happy ... but I'm not. (QVariant is a monster that can contain almost any type of thing)
Motivation:
class RectanglePainter
{
void setDataSource(Data * p_model, int p_widthAttr, int p_heightAttr);
};
Notice that RectanglePainter doesn't know anything about the data object it uses as a source, and I could even hotswap which model and which attributes it uses to draw.
I could give it a rectangle object with width/height, or a circle object with radius/radius or maybe even a human object with weight/height.
Here's what I came up with, I can't find anything decent on google so I'm forced to ask here.
I had a previous question here, but I think people didn't quite understand it and I would have had to change my question too much to get the answers I was looking for.
Aucun commentaire:
Enregistrer un commentaire