Chapter 12: Working with Inheritance


Chapter 12

Working with Inheritance

After completing this chapter, you will be able to:

  • Create a derived class that inherits features from a base class.

  • Control method hiding and overriding by using the new, virtual, and override keywords.

  • Limit accessibility within an inheritance hierarchy by using the protected keyword.

  • Capture common implementation details in an abstract class.

  • Declare that a class cannot be inherited by using the sealed keyword.

  • Create an interface identifying the names of methods.

  • Implement interfaces in a struct or class by writing the bodies of the methods.

Inheritance is a key concept in the world of object-orientation. You can use it as a tool to avoid repetition when defining different classes that have a number of features in common, and are quite clearly related to each other. Perhaps they are different classes of the same type, each with its own distinguishing feature; for example, managers, manual workers, and all employees of a factory. If you were writing an application to simulate the factory, how would you specify that managers and manual workers have a number of features that are the same, but also have other features that are diverse? For example, they all have an employee reference number, but managers have different responsibilities and perform different tasks than manual workers.

This is where inheritance proves useful.




Microsoft Visual C# 2005 Step by Step
Microsoft® Visual C#® 2005 Step by Step (Step By Step (Microsoft))
ISBN: B002CKYPPM
EAN: N/A
Year: 2005
Pages: 183
Authors: John Sharp

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net