Design question - loading info from DB

Posted by eriks on Stack Overflow See other posts from Stack Overflow or by eriks
Published on 2010-03-21T08:53:30Z Indexed on 2010/03/21 9:01 UTC
Read the original article Hit count: 191

Filed under:
|

I need to build a class that will represent a row in some table in DB (lets say the table is 'Subscriber' and so is the class).

  1. I can have the class Subscriber which constructor receives the Objectkey of subscriber, retrieves info from DB and initializes its members.

  2. I add another class - SubscriberLoader which have a static method 'LoadSubscriber'. This method will receive the subscriber objectkey, retrieve info from DB, crate a Subscriber object and initialize its members. Subscriber constructor will be private and SubscirberLoader will be friend class of Subscriber - this way, client could build a Subscriber only using the loader.

which of the two in better? any other suggestions?

© Stack Overflow or respective owner

Related posts about c++

Related posts about design