Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
In this video, we'll introduce our first challenge—creating a base class for our Media Library program media types.
Prerequisites
This practice session assumes that you've completed stage 3 of the C# Objects course. If you haven't done that yet, go check it out, then come back to this workshop.
This practice session also builds upon the skills that are covered in these two practice sessions that cover stages 1 and 2 of the C# Objects course.
If you haven't completed these practice sessions yet, you might consider doing that first before attempting this practice session.
Instructions
1st Challenge
-
Add a MediaType base class to your program.
- Add a public field named
Title
of typestring
. - Add a constructor to the MediaType class.
- Define a parameter named
title
of typestring
. - Initialize the
Title
field using thetitle
parameter.
- Add a public field named
-
Update your existing media type classes to inherit from the MediaType base class.
- Call the base class' constructor from each of the media type subclasses.
-
Review your media type subclasses and remove any
Title
field definitions from those classes.- Remove any constructor initialization code related to the removed
Title
fields.
- Remove any constructor initialization code related to the removed
Help
If you get stuck on any of the following topics or simply need a refresher, click on a topic in list below to view the associated video in the C# Objects course.
- Recall that classes define what it means to be in a particular classification
- Recall that subclasses allow you to refine more general classifications
- Recall that subclasses inherit the attributes and behaviors of more general classes
- Create a subclass of a class
- Call a base class constructor using the
base
keyword
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up