PC Review


Reply
Thread Tools Rate Thread

Create 2 instance with the same name

 
 
Islam Elkhayat
Guest
Posts: n/a
 
      29th Mar 2005
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



 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGFuaWVsIEppbg==?=
Guest
Posts: n/a
 
      29th Mar 2005
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
>
>
>
>

 
Reply With Quote
 
 
 
 
Nick Malik [Microsoft]
Guest
Posts: n/a
 
      29th Mar 2005
Hi Islam,

Use the Factory Method pattern
There's a good tutorial here:
http://www.devhood.com/tutorials/tut...utorial_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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I reveerse name order last name, first name to first name, last name Don Smith Microsoft Excel Discussion 9 29th Nov 2006 10:55 PM
Create 2 instance with the same name Islam Elkhayat Microsoft C# .NET 2 29th Mar 2005 03:55 PM
Start only one instance / open new files in the same instance Arian Haeser Microsoft VB .NET 0 28th Sep 2004 10:41 AM
Activating an open instance of Word without opening a new instance Larry Microsoft Word Document Management 8 12th Nov 2003 06:05 AM
How To Create an instance of an object from another instance? Andro Tan Microsoft Dot NET Framework 2 21st Jul 2003 01:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:24 AM.