Create 2 instance with the same name

Discussion in 'Microsoft 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. Advertisements

  2. Islam Elkhayat

    Guest Guest

    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
    >
    >
    >
    >
     
    Guest, Mar 29, 2005
    #2
    1. Advertisements

  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. Advertisements

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:
    1
    Views:
    178
    Steve C. Orr [MVP, MCSD]
    Jan 12, 2004
  2. Renato Nabinger via DotNetMonster.com

    How do i get the name of a user control instance?

    Renato Nabinger via DotNetMonster.com, Mar 17, 2005, in forum: Microsoft ASP .NET
    Replies:
    0
    Views:
    226
    Renato Nabinger via DotNetMonster.com
    Mar 17, 2005
  3. Replies:
    3
    Views:
    169
    Guest
    May 16, 2006
  4. Matt

    Aspnet Application user same for ever instance

    Matt, May 16, 2006, in forum: Microsoft ASP .NET
    Replies:
    0
    Views:
    152
  5. rodchar

    mvc same name same post

    rodchar, Oct 8, 2009, in forum: Microsoft ASP .NET
    Replies:
    0
    Views:
    191
    rodchar
    Oct 8, 2009
Loading...

Share This Page