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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Classes ❘ 247<br />

Method<br />

AssignJob<br />

PrintInvoice<br />

EstimatedCost<br />

Purpose<br />

Assigns the Job to an Employee<br />

Prints an invoice for the Customer after the job is completed<br />

Calculates and returns an estimated cost based on the customer’s<br />

service contract type and EstimatedHours<br />

The class could provide the events shown in the following table to keep the main program informed<br />

about the job’s progress.<br />

Event<br />

Created<br />

Assigned<br />

Rejected<br />

Canceled<br />

Finished<br />

Purpose<br />

Occurs when the Job is first created<br />

Occurs when the Job is assigned to an Employee<br />

Occurs if an Employee refuses to do the job, perhaps because the<br />

Employee doesn’t have the right skills or equipment to do the work<br />

Occurs if the Customer cancels the job before it is started<br />

Occurs when the job is completed<br />

The class packages the data and behavior of some programming abstraction such as a Job, Employee,<br />

Customer, Menu, SquashMatch, SoftwareProject, or anything else you might want to manipulate as<br />

a single entity.<br />

After you have defined a class, you can create as many instances of the class as you like. An instance<br />

of the class is an object of the class type. For example, the Job class represents jobs in general. After<br />

you have defined the Job class, you can make instances of the class to represent specific jobs. You<br />

could create instances to represent building a brick wall, planting a tree, or repairing a telephone<br />

switch. The process of creating an instance of a class is called instantiation.<br />

There are a couple common analogies to describe instantiation. One compares the class to a blueprint.<br />

After you define the class, you can use it to create any number of instances of the class, much as you<br />

can use the blueprint to make any number of similar houses (instances).<br />

The different houses have much in common. For example, the blueprint defines the number, size, and<br />

relative placement of the houses’ rooms. These are analogous to features defined by the class that apply<br />

to all the instances. (In the Job class example, all instances have a PrintInvoice method that prints<br />

an invoice. Although exactly what is printed depends on the instance’s properties.)<br />

The houses can also have differences such as different colors, front doors, and appliances. Those<br />

correspond to the class’s property values. For example, a House class could define ExteriorColor<br />

and ExteriorTrim properties that determine the color of each instance of the class.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!