views:

162

answers:

5

I have a class called Player in the business layer of my web application.

Player class has fields PlayerID, CategoryID and CountryID

A function in Player Class calls a function in PlayerDB Class in the Data Access Layer which in turn calls a stored proc which returns data for PlayerID, CategoryID (foreign key to Category table) and CountryID(foreign key to Country table) from the Player table.

I now have a situation where I want to add Country Name and Country Image (url path) to the above call, returning the new fields from the Country table for each CountryID.

My question is, do I add the country name and country image as additional fields to the Player class or do I have new classes called Country(BLL) and CountryDB(DAL) and a new stored proc?

I want to do what is best practice rather than what may be the easiest way.

If it is relevant I am using ASP.NET, VB.NET and SQL2005.

As you can probably tell I am a newbie so forgive me if I have not used the correct terminology in my question. I hope you get the idea.

+1  A: 

Create a new class. If it makes sense as a separate logical entity then it should be it's own class.

Davy8
+1  A: 

It sounds like you should probably create a new class.

It does depend on what the use of the "Player" class is. If it's a generic type (and it sounds like it is) that is used in several parts of your app, adding a customisation for a single part of your app into the Player class is probably a bad thing.

However, if (for example) the Player class was used only in a single User Interface in your app, and it's purpose was to represent the Player for that part of the app only, then adding those fields may be reasonable thing to do.

Richard Nichols
A: 

I've found that whenever I have to ask that, the answer is always make a new class. I don't think I've ever seen a system with too many classes, or with two that should have been one.

Ever.

Bill K
+1  A: 

You could make a country class, and using object composition, make the country class a property of the player class.

Public Property Country() as BLL.Country
' etc

Then you'd call the methods like this:

Dim p as BLL.Player
a = p.Country.ID
b = p.Country.Name
c = p.Country.Image
d = p.ID
e = p.CategoryID
HardCode
A: 

How are you going to use the country data? Are you going to always be writing player.getCountry().getName() all the time? If so, you could write a function player.getCountryName() which calls country.getName() internally.

Look into the Law of Demeter, which says you should limit how much your callers know about your internals.

lacqui