A.13. Chapter 15

A.13.1. Exercise 1 Solution

Clearly this is a problem that begs for an inherited solution. The base class would be called clsMembers and would contain all of the information that pertains to all members. That data would include name and mailing address, billing information, and the like. The derived classes would be clsSenior, clsRegular, clsJunior, and clsSocial. Each of these classes would have information that pertains to that class only (dues rate, voting privileges, monthly food minimums, and so on).

A.13.2. Exercise 2 Solution

You can tell that this line of code appears in the clsJunior class and is part of the constructor for the class. You can also tell that the base class has a similar constructor that the writer wants to call as part of setting the initial state of the object. As a general rule, the sequence displayed here is good, because it shows that the writer is being consistent with the initialization of new objects.

A.13.3. Exercise 3 Solution

Their concern is that the derived classes can directly change the value of a data item in the base class without having to be subject to any validation code that might be associated with that property's set method in the base class. This is a real concern.

However, I think the concern, while real, is not serious. Users of the class will still go through the property's set method and only the programmers of the derived classes can abuse this concern. If you can assume that your programming colleagues aren't ...

Get Beginning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.