i have a question: what is better: a class with a number of properties, or a subclass,with the properties, in the 'main class' ? So that every subclass has a couple of properies, not all of them. the properties left can then be in another subclass. please answer quick.
It depends on what you need. If the properties have sense to be together in a single big class you should do so, if they have some 'natural' grouping you should group them in a subclass
My personal opinion is that if the properties you are referring to are phone, street, town, country, etc, then I'd keep them in the Person class and have "sentinel" values for each that indicate the property is unspecified for a given Person instance. For example, an empty string for "town" means the town isn't specified.
For the sake of future maintainability and extensibility, I'd also provide methods on Person that ask if the town, etc.
is specified. For example:
1 2 3 4 5 6 7 8
class Person {
public:
typedef std::string TownName;
private:
TownName town;
public:
bool hasTown() const { return !town.empty(); }
};
This allows you to completely change the implementation details of town later without breaking
any code that uses it.