Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Determine what type of object a GUID belongs to.

Determine what type of object a GUID belongs to.

Scheduled Pinned Locked Moved Visual Basic
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jay Royall
    wrote on last edited by
    #1

    If in my application I have an ID of an object (GUID) and this ID could belong to one of three different types of object, what is the best way to determine which object the ID belongs to? Let me explain a little more. I have 3 classes which inherit from the same super class. Any instance of these three classes can be the owner of a service. Given the service, which has an owner ID, what is the best way to determine the owner? i.e. what type of object. I have some ideas but each one seems to have it's flaws. I thought of having 3 fields in the database table for owner instead of one, one for each type of object but surely this goes against good database design. I thought of having, in the database table, an owner field and an owner type field (this seems the best way so far). Or, in my aplication, try to instantiate each class using the ID, the one that works wins! But this doesn't seem very efficient at all! Any advice is appreciated. Thanks.

    D L 2 Replies Last reply
    0
    • J Jay Royall

      If in my application I have an ID of an object (GUID) and this ID could belong to one of three different types of object, what is the best way to determine which object the ID belongs to? Let me explain a little more. I have 3 classes which inherit from the same super class. Any instance of these three classes can be the owner of a service. Given the service, which has an owner ID, what is the best way to determine the owner? i.e. what type of object. I have some ideas but each one seems to have it's flaws. I thought of having 3 fields in the database table for owner instead of one, one for each type of object but surely this goes against good database design. I thought of having, in the database table, an owner field and an owner type field (this seems the best way so far). Or, in my aplication, try to instantiate each class using the ID, the one that works wins! But this doesn't seem very efficient at all! Any advice is appreciated. Thanks.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The best way (given the limited explanation you have), would be a lookup table. Store the ID and the object it belongs to, or the object type, in some structure. Trying to create an object to "see if it works" is probably the worst way you can go about this.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      J 1 Reply Last reply
      0
      • D Dave Kreskowiak

        The best way (given the limited explanation you have), would be a lookup table. Store the ID and the object it belongs to, or the object type, in some structure. Trying to create an object to "see if it works" is probably the worst way you can go about this.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        J Offline
        J Offline
        Jay Royall
        wrote on last edited by
        #3

        OK great, thanks for your help.

        1 Reply Last reply
        0
        • J Jay Royall

          If in my application I have an ID of an object (GUID) and this ID could belong to one of three different types of object, what is the best way to determine which object the ID belongs to? Let me explain a little more. I have 3 classes which inherit from the same super class. Any instance of these three classes can be the owner of a service. Given the service, which has an owner ID, what is the best way to determine the owner? i.e. what type of object. I have some ideas but each one seems to have it's flaws. I thought of having 3 fields in the database table for owner instead of one, one for each type of object but surely this goes against good database design. I thought of having, in the database table, an owner field and an owner type field (this seems the best way so far). Or, in my aplication, try to instantiate each class using the ID, the one that works wins! But this doesn't seem very efficient at all! Any advice is appreciated. Thanks.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Liqz wrote:

          I thought of having, in the database table, an owner (ID?) field and an owner type field (this seems the best way so far).

          You thought correctly, it enables you to lookup the type based on the OwnerID without storing duplicates :) It is dangerous to instantiate something that you do not know - since it might, for example, delete all records in a table on startup, as initialization. Even if you're sure that nothing can go wrong, then it would still be slow, as you already stated.

          Liqz wrote:

          what is the best way to determine the owner? i.e. what type of object.

          If you can't ask the owner-object itself, then you'll have to resort to keeping track of that information elsewhere. Like tracking it in a database :thumbsup:

          I are troll :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups