Create 2 instance with the same name

Discussion in 'ASP .Net' started by Islam Elkhayat, Mar 29, 2005.

  1. I have to 2 Data classes have the same methods with defferent implemention
    which work with 2 tables in the database..
    I want to chnge the instance referance depend on if condition or switch
    case..
    like this...

    myclass.AddRow()

    where my class can be instance of Categories or Employees so i don't have to
    write the same code twice..
    I tried Activator.CreateInstance(); which return an object but i couldn't
    access methods..
    Is there a way to make it work??
    thanx
    Islam Elkhayat, Mar 29, 2005
    #1
    1. Advertising

  2. have them either both inherit from the same base class or both implement a
    common interface. whichever makes more sense in your situation.

    "Islam Elkhayat" wrote:

    > I have to 2 Data classes have the same methods with defferent implemention
    > which work with 2 tables in the database..
    > I want to chnge the instance referance depend on if condition or switch
    > case..
    > like this...
    >
    > myclass.AddRow()
    >
    > where my class can be instance of Categories or Employees so i don't have to
    > write the same code twice..
    > I tried Activator.CreateInstance(); which return an object but i couldn't
    > access methods..
    > Is there a way to make it work??
    > thanx
    >
    >
    >
    >
    =?Utf-8?B?RGFuaWVsIEppbg==?=, Mar 29, 2005
    #2
    1. Advertising

  3. Hi Islam,

    Use the Factory Method pattern
    There's a good tutorial here:
    http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=645


    --
    --- Nick Malik [Microsoft]
    MCSD, CFPS, Certified Scrummaster
    http://blogs.msdn.com/nickmalik

    Disclaimer: Opinions expressed in this forum are my own, and not
    representative of my employer.
    I do not answer questions on behalf of my employer. I'm just a
    programmer helping programmers.
    --
    "Islam Elkhayat" <> wrote in message
    news:...
    >I have to 2 Data classes have the same methods with defferent implemention
    > which work with 2 tables in the database..
    > I want to chnge the instance referance depend on if condition or switch
    > case..
    > like this...
    >
    > myclass.AddRow()
    >
    > where my class can be instance of Categories or Employees so i don't have
    > to
    > write the same code twice..
    > I tried Activator.CreateInstance(); which return an object but i couldn't
    > access methods..
    > Is there a way to make it work??
    > thanx
    >
    >
    >
    Nick Malik [Microsoft], Mar 29, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    477
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    May 16, 2006
  2. Sandra-24
    Replies:
    18
    Views:
    1,837
    Steve Holden
    Apr 29, 2006
  3. Replies:
    5
    Views:
    330
    Alf P. Steinbach
    Feb 6, 2006
  4. Replies:
    0
    Views:
    322
  5. Ralph Shnelvar

    Same name for class and instance method

    Ralph Shnelvar, Nov 22, 2009, in forum: Ruby
    Replies:
    1
    Views:
    85
    Robert Klemme
    Nov 22, 2009
Loading...

Share This Page