1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Design question

Discussion in 'Mathematics and Physics' started by electroRF, Jan 24, 2014.

  1. electroRF

    electroRF Member

    Joined:
    Jun 23, 2012
    Messages:
    689
    Likes:
    9
    Location:
    Portugal
    Hi,

    I'm trying to solve the following exercise and looking for an approaching idea.

    a computer store needs a mechanism to enable identifying each item in its stock.

    i.e. a specific computer will have different ID than other computers and also than other printers / keyboards, etc.

    i need to create a class UniqueID that provides the above requirement.

    then, I'll create a few classes that represent items, and the classes will use the UniqueID mechanism and get a unique ID.

    You have an idea how to design the UniqueID mechanism?

    Thank you.
    ---
    I thought of:

    1. creating a UniqueID class, that has static long long m_id; which will be initialized to 0.

    2. every item's class will have a data member long long m_id;

    3. the constructor will perform:
    - - - this->m_id = UniqueID::m_id;
    - - - UniqueID::m_id++;

    But i'm not sure if it's a good approach.

    long long supports 2^64 items' IDs, which is a reasonable limit, and will never be exceeded.
     
    Last edited: Jan 24, 2014
  2. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,913
    Likes:
    1,095
    ONLINE
    That's why they put serial numbers on the outside of the box. It's an inherent unique ID. They bar code them too. So, you have SKU and s/n.
     
  3. electroRF

    electroRF Member

    Joined:
    Jun 23, 2012
    Messages:
    689
    Likes:
    9
    Location:
    Portugal
    hi KISS
    Thank you.

    Could you please elaborate on your approach?

    I'm not sure how you suggested the design to be.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,913
    Likes:
    1,095
    ONLINE

    What I am saying is that some things that you buy in the store already come with a unique ID and that ID would be the SKU code combined with the serial number of the unit.

    I'm using existing information which is usually encoded on the box.

    Well, probably UPC or SKU and/or s/n see: http://www.ask.com/question/what-is-the-difference-between-sku-and-upc
     

Share This Page