473,387 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Create Instance

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
Nov 17 '05 #1
1 1583
You can use polymorphism.
Create an interface or an abstract class A.
Then make classes B and C implement or inherit A.
At run time you can create a new instance like this:

if(condition)
{
A instanceName = new B();
}
else
{
A instanceName = new C();
}

The rest of the code simply relates to A,
activating a different method according to the instance type.

If you choose an abstract class, you need to declare
methods as virtual, and override them.

"Islam Elkhayat" <Is******@SaveMyPrivacy.bye> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl...
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

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: cat | last post by:
HiFolks, I am newbie in DB2 ESE. Here is the question, I already created an instance db2inst1 under file system /db2home/db2inst1 ( actually the instance has been created after installation.)...
20
by: Hemant Shah | last post by:
Folks, I am using DB2 UDB 8.2 on AIX 5.1. How large of a bufferpool can you create? I tried to create a 4GB bufferpool db2 complained that is cannot allocate enogth memory. I have 16GB on this...
2
by: Markus Prediger | last post by:
Hi NG, I have an asp.net project that uses an vb6 com object for some database-manipulation (I cannot rewrite it in .net, sorry, its not my decision). I want it to be instanciated seperately...
4
by: Joe HM | last post by:
Hello - I have a Base Class where I want a New() implemented that can be called from the outside. This New() should create an instance of the appropriate cDerivedX Class ... The following...
1
by: otto | last post by:
I have a technical question about WebServices. I have a solution with several projects (.exe and .dll). Each project have references to several webservices. I want to know if is possible to create...
3
by: fyi85 | last post by:
I am trying to create a server on the same machine running the same instance. This is v8.1.5 on Windows 2003 Server. The instance is set to FEDERATED=YES The server will be created for database...
6
by: madpython | last post by:
For the pure theory sake and mind expansion i got a question. Experimenting with __new__ i found out how to create a singleton. class SingleStr(object): def __new__(cls,*args,**kwargs):...
5
by: Philip Nelson | last post by:
I get - db2inst1@dvorak /db2data $ db2 "create database DBTST001 automatic storage yes on /db2data/db2db dbpath on /db2data/db2db" SQL0805N Package "NULLID.SQLE2F0J 0X4141414141654557" was not...
2
by: Angel Of Death | last post by:
I have a method. It takes some XML as a parameter. Depending on the content of the XML it should create a specific object and call a KNOWN method. So: public void PersistXml(string XmlData){} ...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.