developer.com
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
New
 
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




Vote for the Developer.com Product of the Year Winners!




Developer Jobs

Be a Commerce Partner














 


Developer News -
The Year of Living the OpenSocial    November 14, 2008
Firefox Fixes New and Older Versions    November 13, 2008
Can Apache Maven Make It by Going Commercial?    November 12, 2008
Novell Goes After Red Hat Linux Users    November 11, 2008
Free Tech Newsletter -

Learning C# and OOP: Getting Started, Objects and Encapsulation
By Richard G. Baldwin

Go to page: Prev  1  2  3  

Summary

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#.

Answer

2.  True or false?  You can run the .NET Framework SDK on Windows 98.

Answer

3.  True or false?  You must download the documentation for the .NET Framework SDK as a separate download package.

Answer

4.  True or false?  You can compile and execute C# programs either from within an IDE, or directly from the Windows command line.

Answer

5.  List the three pillars of OOP.

Answer

6.  Describe an object-oriented program.

Answer

7.  Describe a software object.

Answer

8.  Describe encapsulation.

Answer

9.  Explain why a car radio is an imperfect, but good analogy to a software object.

Answer

10.  What is the physical manifestation of sending a message to an object in C#?

Answer


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.

baldwin@DickBaldwin.com


Answers

Answer 10

As a practical matter, the physical manifestation of sending a message to an object in C# is to cause that object to execute one of its methods.

Back to Question 10

Answer 9

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.

Back to Question 9

Answer 8

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."
Back to Question 8

Answer 7

A software object is a software construct that encapsulates data (into a software entity), along with the ability to use or modify that data.

Back to Question 7

Answer 6

Many authors would describe an object-oriented program something like the following:
An Object-Oriented Program consists of a group of cooperating objects, exchanging messages, for the purpose of achieving a common objective.
Back to Question 6

Answer 5

Most books on OOP will tell you that in order to understand OOP, you need to understand the following three concepts:
  • Encapsulation
  • Inheritance
  • Polymorphism
Back to Question 5

Answer 4

True

Back to Question 4

Answer 3

False.  According to Microsoft,
"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."
Back to Question 3

Answer 2

False.  According to Microsoft, the .NET Framework SDK runs on:
  • Microsoft Windows NT® 4.0 (SP 6a required)
  • Microsoft Windows® 2000 (SP 2 recommended)
  • Microsoft Windows XP Professional
Back to Question 2

Answer 1

False.  All you need to get started programming using C# is the free Microsoft® .NET Framework Software Development Kit (SDK) and a simple text editor.

Back to Question 1



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.

-end-

Go to page: Prev  1  2  3  

Next article: Learning C# and OOP, Classes


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


.NET Archives






internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers