15.01.2013 Views

Foundations of Programming - Karl Seguin

Foundations of Programming - Karl Seguin

Foundations of Programming - Karl Seguin

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.

Chapter 3 - Persistence<br />

public class Upgrade<br />

{<br />

private int _id;<br />

private string _name;<br />

private string _description;<br />

private decimal _price;<br />

private List _requiredUpgrades;<br />

}<br />

public int Id<br />

{<br />

get { return _id; }<br />

internal set { _id = value; }<br />

}<br />

public string Name<br />

{<br />

get { return _name; }<br />

set { _name = value; }<br />

}<br />

public string Description<br />

{<br />

get { return _description; }<br />

set { _description = value; }<br />

}<br />

public decimal Price<br />

{<br />

get { return _price; }<br />

set { _price = value; }<br />

}<br />

public List RequiredUpgrades<br />

{<br />

get { return _requiredUpgrades; }<br />

}<br />

We’ve added the basic fields you’d likely expect to see in the class. Next we’ll create the table that<br />

would hold, or persist, the upgrade information.<br />

CREATE TABLE Upgrades<br />

(<br />

Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY,<br />

[Name] VARCHAR(64) NOT NULL,<br />

Description VARCHAR(512) NOT NULL,<br />

Price MONEY NOT NULL,<br />

)<br />

No surprises there. Now comes the interesting part (well, relatively speaking), we’ll start to build up our<br />

data access layer, which sits between the domain and relational models (interfaces left out for brevity)<br />

<strong>Foundations</strong> <strong>of</strong> <strong>Programming</strong> Copyright © <strong>Karl</strong> <strong>Seguin</strong> www.codebetter.com<br />

21

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

Saved successfully!

Ooh no, something went wrong!