Код: Выделить всё
class ChartBase {
private:
int transparency; //chart attribute
};
class XYChart : public ChartBase{
private:
std::string xAxis;
std::string yAxis;
};
class LineChart : public XYChart
{
private:
int lineWidth;
int lineColor;
};
Код: Выделить всё
class StyleBase {
private:
int transparency;
};
class XYStyle : public StyleBase {
private:
std::string xAxis;
std::string yAxis;
};
class LineStyle : public XYStyle {
private:
int lineWidth;
int lineColor;
};
class ChartBase {
protected:
std::shared_ptr style;
};
- в производном классе, таком как LineChart, если вы хотите что-то сделать с lineWidth, Затем цвету необходимо привести указатель стиля к LineStyle для доступа к атрибуту lineWidth и lineColor.
- каждый производный класс ChartBase в своем конструкторе создаст экземпляр StyleBase, как показано ниже.
Код: Выделить всё
class ChartBase{
public:
ChartBase() { style = new StyleBase;}
};
class XYChart : public ChartBase{
public:
XYChart() {style = new XYStyle;}
};
class LineChart : public XYChart {
public:
LineChart() { style = new LineStyle;}
};
есть ли есть лучший дизайн? или нам не следует извлекать их из диаграммы?
Подробнее здесь: https://stackoverflow.com/questions/786 ... ther-class