Inheritance

The next pillar of OOP is inheritance. Now that we have nice encapsulation of functionality in a (class) type, what about reusing it for other types? There are two ways to do this. One is to wrap the use of one type in another one. For example, a customer tracking system may use a counter to keep track of the number of current visitors in an online store.

However, this containment mechanism is not very different from any other use of a counter elsewhere in the code. In fact, our customer-tracking system (implemented as another class) encapsulates a counter and may expose some of the counter’s operations to the outside world. For example, our counter could have a Count get-only property that may simply be exposed on the customer-tracking ...

Get C# 4.0 Unleashed 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.