03.01.2015 Views

C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

246 ❘ CHAPTER 11 OOP Concepts<br />

The three main sets of characteristics of a class are the properties, methods, and events that it<br />

defines. The public (externally visible) properties, methods, and events let the program work with<br />

the class:<br />

➤➤<br />

➤➤<br />

➤➤<br />

A property is some sort of data value. It may be a simple value (such as a string or int), or<br />

it may be a more complex item (such as an array, list, or object containing its own properties,<br />

methods, and events). Properties determine some feature of an object such as its name, color,<br />

or behavior.<br />

A method is a routine that performs some action. A method makes an object defined by the<br />

class do something.<br />

An event provides notification that something happened to an object defined by the class. An<br />

event can invoke other pieces of code to tell other parts of the program that something has<br />

happened to the object.<br />

For a concrete example, imagine a Job class that represents a piece of work to be done by an<br />

employee. This class might have the properties shown in the following table.<br />

Property<br />

JobDescription<br />

EstimatedHours<br />

ActualHours<br />

Status<br />

ActionTaken<br />

Customer<br />

AssignedEmployee<br />

Purpose<br />

A string describing the job.<br />

The number of hours initially estimated for the job.<br />

The actual number of hours spent on the job.<br />

An enumeration giving the job’s status (New, Assigned,<br />

InProgress, or Complete).<br />

A string describing the work performed, parts installed, and<br />

so forth.<br />

An object of the Customer class that describes the customer for<br />

whom the job is performed. (That class has properties such as<br />

Name, Address, PhoneNumber, and ContractNumber.)<br />

An object of the Employee class that describes the employee<br />

assigned to the job. (That class has properties such as Name,<br />

PhoneNumber, EmployeeId, and SocialSecurityNumber.)<br />

The JobDescription, EstimatedHours, ActualHours, Status, and ActionTaken properties are<br />

relatively simple string and numeric values. The Customer and AssignedEmployee properties<br />

are objects themselves with their own properties, methods, and events.<br />

This Job class might provide the methods shown in the following table.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!