Here is an initial specification for a simple Address class. This is a simplification as it ignores complications such as apartments in the same building potentially having the same ‘number’,
e.g. 29a, 29b.
class Address
{
private:
int number;
string name;
string postcode;
public:
//getters implemented but ommited
};
If Address is suppose to served as an utility class (possible future use in other projects by other developers):
//QUESTION
1. For each attribute of Address given in the specification above, state whether it would be appropriate to equip the Address class with a setter method for the corresponding instance variable. Give a brief justification in each case.
Guys this is a question from my assignment so please do not question the way class Address is designed.
Depends on the source of Address. If, say, you read it from a database, then I wouldn’t implement setters as you don’t want people changing your database values without the correct permissions. If, however, you read this data in from the user, then you will have to account for the fact that users make typos and adjustments or realize they entered their old address or any of that, and you must provide for the changes.