Chapter 9. Designing Classes

In Chapter 2, I stated that classes are like cookie cutters. I went on to point out that Visual Studio provides you with a room full of cookie cutters hanging on the wall that you can use. You have used many of those cookie cutters in the sample programs, including labels, textboxes, buttons, listboxes, and listview objects, all of which are extensions of the basic Windows Forms class. Up to this point, you've been writing code that uses those objects in a single class that I have consistently named frmMain. I called it that because all the programs used a single class containing the Main() method that marks the starting point for all C# programs.

Well, it's time to cut the apron strings.

In this chapter, you will learn how to make your own cookie cutters to hang on the wall. This chapter concentrates on the design considerations you need to think about in order to write "good" code for your own classes. A well-designed class becomes another cookie cutter that you can hang on the wall and use over and over in other programs. Poorly designed classes tend to become use-once-and-throw-away cookie cutters. Given that one of the major advantages of OOP is code reuse, you need to think about class design anytime the opportunity presents itself.

In this chapter, you will learn about:

  • What elements constitute good class design

  • Scope

  • The static storage class

  • Access specifiers

  • Class properties and methods

  • Class components and writing style

  • UML Light

  • General versus ...

Get Beginning C# 3.0 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.