For Programmers: Free Programming Magazines  


Home > Archive > C# > January 2006 > System Design - Entity Classes









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author System Design - Entity Classes
discussions@avandis.co.uk

2006-01-10, 4:10 am

Dear All,

I have a question relating to the design of system which will use
"Custom Entity Classes".

If we use the following example whereby I want to display user details
on a page.

In my ASPX codebehind file I will write:

Users oUsers = new Users();
User oUser = oUsers.Read(UserID);
// Now I can access all the User properties and display them on the
page.

My User Business Class (Users) will have:

public Read(int UserID)
{
DataAccessor oDA = new DataAccessor();

DataRow dr = oDA.ReadUser(UserID);

//Call a method to populate a new User object.
User oUser = PopulateUser(dr);

return oUser;
}

My entity class will have:

public class User
{
private string _FirstName;

public string FirstName
{
get{return _FirstName;}
set{_FirstName = value;}
}
.... other properties here ...
}

Now my specific questions are:

1. Is it right that I should return a DataRow from the DataLayer to the
business layer? Should the Data Class be responisble for returning a
User object instead?
2. Where should my PopulateUser() method be placed - in the User
Business Class (UserBusinessClass) or the Data Class (DataAccessor)?
3. I am going to use one Data Class to return all data for all my
objects - should I instead have one for each Business Class?

Thanks for your help in advance,

Jose

NuTcAsE

2006-01-10, 4:10 am

See inline...

1. Is it right that I should return a DataRow from the DataLayer to the

business layer? Should the Data Class be responisble for returning a
User object instead?

For maximum decoupling between layers the approach you mentioned is
right. Returning DataRows from the data layer may seem extra overhead,
but it leads to max flexibility when changes and maintainance is
required.

2. Where should my PopulateUser() method be placed - in the User
Business Class (UserBusinessClass) or the Data Class (DataAccessor)?

PopulateUser method should be in your business class. The data access
layer should not know anything about your business classes. The data
access layer's pimary function is to encapsluate the logic of data
access thats it.

3. I am going to use one Data Class to return all data for all my
objects - should I instead have one for each Business Class?

It depends on the complexity of your business objects. When returning
data for multiple nested (or related) business objects, the one data
class approach doesnt cut it.

The only thing id change in the sample code you posted is make the Read
method of the User class static. There is no reason to create an
instance of the User class then having call Read which returns another
instance. Either the Read function should be static and return an
instance of the User class, or the Read function just populates the
member variables of the instance the function is called on.

Hope this helps...

Ritesh

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com