Thread: Question: Class relationships

  1. #1
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200

    Question: Class relationships

    I would like to understand the best way to accomplish the relation between two entities.

    Let's say we have an Account and a Customer. Every customer will have one account. Every account may have one or more customers.

    For example:
    Joe's Burgers is the account.
    Joe's Burgers on 1st St. is a customer to the account.
    Joe's Burgers on 2nd St. is a customer on the account.

    In a database the Customers would have an account number that would link to the Joe's Burgers account.

    Would it be best to have two independant classes or should they be connected in some way.

    An example of how the classes would be used:

    Code:
    Customer customer(custNo);
    char* name = customer.getName();
    
    // and I am thinking something like
    Account acct(customer.getAcctNo);
    The difference is, is that the Account would contain billing information while the customer may contain delivery information.

    I hope I made some sense there.


    [edit]
    The more I tihnk about it the more I am thinking I should just have two non related classes. I can get the account number from the Customer class and I would need to be able to get the Customer numbers from the Account class also. So I am not seeing how a relationship would make much sense. I'll leave this open incase i'm deadly wrong!
    Last edited by Vicious; 04-03-2008 at 03:03 PM.
    What is C++?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    They should be two classes. Account should probably also contain a vector of Customer classes. The customer class contains all information about the customer (name, address, etc).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    That makes sense, thank you.
    What is C++?

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    There is an account. There is a customer. And there is a relationship between the account and the customer. This relationship itself could be modeled as a class, so you would have three components, not two.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  2. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. question about DLL's and class functions
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 02-25-2003, 06:08 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM