Determine Object Type From Database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan

    #1

    Determine Object Type From Database

    All,

    I am working on an application that allows users to track
    various items for various clients. For example Client A
    may have an object Box where Client B has an object
    Canister. When a user goes to enter a new object I would
    like the application to determine what objects are
    available based upon the client (easy enough) and when
    they determine what object to enter the program would know
    that it needed to instantiate an object of that type. For
    example, the user selects Client A and object Box the
    program would instantiate an object of type Box. I want to
    avoid hardcoding this into the application so that way if
    I need to add object of type Carton later on I can insert
    that object into the database, distribute a DLL for that
    object, and the program would be able to instantate
    objects of the type canister.

    Does anyone have any idea if this is possible to do and if
    so how? Any suggesions would be greatly appreciated.
    Thanks!
  • Dino Chiesa [Microsoft]

    #2
    Re: Determine Object Type From Database

    Sounds to me like the database is not a central issue in this problem.
    Getting the name of the type from the db is pretty simple, and I'll guess
    that is not what is puzzling you.

    What you seem to be asking for, is a way to instantiate types, selecting the
    implementation of the type dynamically, at runtime.
    You can do this via the System.Activato r.CreateInstanc e() method, or via
    Reflection with the System.Type.Cre ateInstance()
    Check the archives of this group for tips .

    You'll probably want to use interfaces to construct your extensible object
    model, and employ a Factory pattern.
    eg,


    suggestion: google for "factory CreateInstance interface"

    --
    Dino Chiesa
    Microsoft Developer Division
    d i n o c h @ o n l i n e . m i c r o s o f t . c o m

    "Dan" <ddeluca@fnisol utions.com> wrote in message
    news:142001c391 b7$5ff377e0$a00 1280a@phx.gbl.. .[color=blue]
    > All,
    >
    > I am working on an application that allows users to track
    > various items for various clients. For example Client A
    > may have an object Box where Client B has an object
    > Canister. When a user goes to enter a new object I would
    > like the application to determine what objects are
    > available based upon the client (easy enough) and when
    > they determine what object to enter the program would know
    > that it needed to instantiate an object of that type. For
    > example, the user selects Client A and object Box the
    > program would instantiate an object of type Box. I want to
    > avoid hardcoding this into the application so that way if
    > I need to add object of type Carton later on I can insert
    > that object into the database, distribute a DLL for that
    > object, and the program would be able to instantate
    > objects of the type canister.
    >
    > Does anyone have any idea if this is possible to do and if
    > so how? Any suggesions would be greatly appreciated.
    > Thanks![/color]


    Comment

    Working...