This is the first in a miniseries of lessons that describe and discuss
the necessary and most significant aspects of OOP using C#. This
lesson was broken into two major and generally unrelated sections.
The first section dealt with the mechanics of getting started programming
in C#. The second section dealt with the concepts involved in getting
started in OOP.
The mechanics
It is not necessary to spend a lot of money for a high-level development
environment to begin writing object-oriented programs using C#. I
provided you with the information needed to download everything you need,
for free. In addition, I discussed the installation and testing of
those free development tools.
The concepts
In order to understand OOP, you need to understand the following three
concepts:
Encapsulation
Inheritance
Polymorphism
This lesson has concentrated on encapsulation. Encapsulation was
used as a springboard for a discussion of objects.
A description of an object-oriented program was provided, along with
a description of an object, and how it relates to encapsulation.
A real-world analogy
In order to relate object-oriented programming to the real world, a
car radio was used to illustrate and discuss several aspects of software
objects. You learned that car radios, as well as software objects,
have the ability to store data, along with the ability to modify or manipulate
that data.
You learned that car radios, as well as software objects, have the ability
to accept messages, which results in performing an action, modifying state,
returning a value, or some combination of the above.
Jargon, jargon, jargon
You learned some of the jargon used in OOP, including persistence, state,
messages, methods, and behaviors.
Where do objects come from?
You learned where objects come from, and you learned that a class
is a set of plans that can be used to construct objects. (You
also learned that a struct is a set of plans that can be used to construct
objects, but I didn't discuss that in detail. This is one of the
differences between C# and Java.) You learned that a C# object
is an instance of a class or an instance of a struct.
A little bit of code
You saw a little bit of C# code, used to create an object, and then
to send a message to that object (invoke a method on the object).
You learned about C# references and reference variables. You learned
a little about memory allocation for objects and variables in C#.
What's Next?
The next lesson in the miniseries will introduce you to the C# class.
Continuing with the real-world example introduced in this lesson, the
next lesson will provide a complete C# program that simulates the manufacture
and use of a car radio.
Review Questions
1. True or false? You must purchase Microsoft's
Visual Studio development tool to begin programming using C#.
Richard Baldwin
is a college professor (at Austin Community College in Austin, Texas) and
private consultant whose primary focus is a combination of Java, C#, and
XML. In addition to the many platform and/or language independent benefits
of Java and C# applications, he believes that a combination of Java, C#,
and XML will become the primary driving force in the delivery of structured
information on the Web.
Richard has participated in numerous consulting projects, and he
frequently provides onsite training at the high-tech companies located
in and around Austin, Texas. He is the author of Baldwin's Programming
Tutorials,
which has gained a worldwide following among experienced and aspiring programmers.
He has also published articles in JavaPro magazine.
Richard holds an MSEE degree from Southern Methodist University and
has many years of experience in the application of computer technology
to real-world problems.
A car radio has the ability to store data, and to allow you to use and
modify that data at will. However, you can only use and modify that
data through use of the operator interface that is provided by the manufacturer
of the radio. These are also the characteristics of a software object.
According to Rocky Lhotka in an article regarding VB.NET:
"Encapsulation is the concept that an object should totally
separate its interface from its implementation. All the data and implementation
code for an object should be entirely hidden behind its interface."
"The Microsoft® .NET Framework Software Development
Kit (SDK) includes the .NET Framework, as well as everything you need to
write, build, test, and deploy .NET Framework applicationsdocumentation,
samples, and command-line tools and compilers."
Copyright 2002, Richard G. Baldwin. Reproduction in whole or
in part in any form or medium without express written permission from Richard
Baldwin is prohibited.
Add www.developer.com to your favorites Add www.developer.com to your browser search box IE 7 | Firefox 2.0 | Firefox 1.5.xReceive news via our XML/RSS feed