Actually, when you buy a car, you yourself choose a car and a set of options (music, interior, etc.). As in real life, you can enter “options” in your car class. In a simple case, it looks like (C ++):
class Car {
enum CarOptions {
Bumper,
...
};
...
int options() const { return m_options; }
void setOptions(int options) { m_options = options }
...
};
Car c;
c.setOptions(c.options() | Car::Bumper);
Of course, this solution has its pros and cons, like any other.
source
share