Sealing Virtual Members
Recall that the sealed keyword can be applied to a class type to prevent other types from extending
its behavior via inheritance. As you may remember, we sealed PTSalesPerson as we assumed it
made no sense for other developers to extend this line of inheritance any further.
On a related note, sometimes you may not wish to seal an entire class, but simply want to pre-
vent derived types from overriding particular virtual methods. For example, assume we do not want
part-time salespeople to obtain customized bonuses. To prevent the PTSalesPerson class from over-
riding the virtual GiveBonus() method, we could effectively seal this method in the SalesPerson
class as follows:
Do'stlaringiz bilan baham: |