Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

Question on OO best practices with Foreiqn keys

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BillG - 19 Oct 2007 21:49 GMT
I have pondered this question often and have done it several ways but I am
wondering what is the correct OO way to handle this.

In my SQL Sever database I have the following tables for example,

Member and MemberStatus

Member status has two fields StatusCd and Description.  ex. 'A' and
'Active', 'I' and 'Inactive'

Member has a field called Status that tracks the status of that member.
What is the proper way to create this class?

public class Member
{
     private string m_SocSecNo;
     private string m_LastName;
     private string m_FirstName;
(A)     private string m_StatusCd or

(B)     private MemberStatus m_MemberStatus

(C)    private string m_StatusCd;
         private string m_StatusDescription;

}

public class MemberStatus
{
      private string m_StatusCd;
      private string m_Description;
}

Thanks
Bill
Jon Skeet [C# MVP] - 19 Oct 2007 22:20 GMT
> I have pondered this question often and have done it several ways but I am
> wondering what is the correct OO way to handle this.
[quoted text clipped - 8 lines]
> Member has a field called Status that tracks the status of that member.
> What is the proper way to create this class?

How many possible statuses are there? I would probably either use an
enum for the MemberStatus, or a class but with a private constructor
and a few predefined immutable values (so that you can still have both
the code and the description).

I certainly wouldn't put them both in Member.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

BillG - 19 Oct 2007 22:30 GMT
There could be 5 or 6 different statuses and I don't necessarily know what
they are.  They could be different for different clients so I can't create
an enum.  This is also just an example. It could be a case like this

public class Customer
{
   private int m_Id;
   private string m_CustomerName;
   private string m_SalesPersonId;

   or

   private SalesPerson m_SalesPerson;

}

public class SalesPerson
{
   private string m_Id;
   private string m_LastName;
   private string m_FirstName;
   private string m_Telephone;
}

>> I have pondered this question often and have done it several ways but I
>> am
[quoted text clipped - 16 lines]
>
> I certainly wouldn't put them both in Member.
Jon Skeet [C# MVP] - 19 Oct 2007 22:39 GMT
> There could be 5 or 6 different statuses and I don't necessarily know what
> they are.  They could be different for different clients so I can't create
> an enum.

Ah, rats. Ah well - it would save memory to have a fixed set of
flyweights, but loading them isn't too bad.

>  This is also just an example. It could be a case like this
>
[quoted text clipped - 9 lines]
>
> }

I'd prefer a proper class reference, again.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Cor Ligthert[MVP] - 20 Oct 2007 10:45 GMT
Bill,

Why are you not just using booleans (bit in SQL server)?

Seems for me to make it difficult especially to maintain not using the right
types for the meant purposes.

Cor

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.