5.2. Rules for Deriving Classes: The "Do's"

When deriving a new class, we can do several things to specialize the base class that we are starting out with:

  • We can extend the base class by adding members. In our GraduateStudent example, we added four members: two fields—undergraduateDegree and undergraduateInstitution—and two properties—UndergraduateDegree and UndergraduateInstitution.

  • We can specialize the way that a derived class performs one or more of the methods inherited from its base class. For example, when "general" students enroll for a course, the students may first need to ensure that

    • They have taken the necessary prerequisite courses.

    • The course is required for the degree that the student is seeking.

    • When graduate students enroll for ...

Get Beginning C# 2008 Objects: From Concept to Code 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.