Information Technology Reference
In-Depth Information
3
Expressing Designs in C#
Beginners using a foreign (human) language can manage to communi-
cate. They know the words, and they can piece them together to get their
point across. As beginners transition to experts in a language, they begin
to use the proper idioms in this foreign language. The language becomes
less foreign, and the person begins speaking more efficiently and more
clearly. Programming languages are no different. The techniques you
choose communicate your design intent to the developers who maintain,
extend, or use the software you develop. C# types all live inside the .NET
environment. The environment makes some assumptions about the capa-
bilities of all types as well. If you violate those assumptions, you increase
the likelihood that your types won't function correctly.
The items in this chapter are not a compendium of software design tech-
niques—entire volumes have been written about software design. Instead,
these items highlight how different C# language features can best express
the intent of your software design. The C# language designers added lan-
guage features to more clearly express modern design idioms. The dis-
tinctions among certain language features are subtle, and you often have
many alternatives to choose from. More than one alternative might seem
“best” at first; the distinctions show up only later, when you find that you
must enhance an existing program. Make sure you understand these items
well, and apply them carefully with an eye toward the most likely enhance-
ments to the systems you are building.
Some syntax changes give you new vocabulary to describe the idioms you
use every day. Properties, indexers, events, and delegates are examples, as
is the difference between classes and interfaces: Classes define types. Inter-
faces declare behavior. Base classes declare types and define common
behavior for a related set of types. Other design idioms have changed
because of the Garbage Collector. Still others have changed because most
variables are reference types.
The recommendations in this chapter will help you pick the most natural
expression for your designs. This will enable you to create software that is
easier to maintain, easier to extend, and easier to use.
125
 
 
 
Search WWH ::




Custom Search