473,396 Members | 2,023 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,396 software developers and data experts.

dynamic classes

Hi

I have 2 classes, layout1 and layout2, both return different table layouts

In my controlling program I create one of these tables using

Table myTable = new layout1

I need to parameterise the 'layout1' part of this statement, so I can choose a different layout at runtime. Is this possible or is there a better way of doing this

Thank
Kieran
Jul 21 '05 #1
3 1350
Table myTable;
if (...) myTable = new layout1 else myTable = new layout2;

I'm not really sure if I got your question...

Niki

"Kieran" <an*******@discussions.microsoft.com> wrote in
news:B3**********************************@microsof t.com...
Hi,

I have 2 classes, layout1 and layout2, both return different table layouts.
In my controlling program I create one of these tables using:

Table myTable = new layout1;

I need to parameterise the 'layout1' part of this statement, so I can choose a different layout at runtime. Is this possible or is there a better
way of doing this?
Thanks
Kieran

Jul 21 '05 #2
Hi

Thanks for your reply, I was hoping though to feed in the class name though, e.

string myClass = 'layout1

Table myTable = new myClas

I know the above wont work but I hope this explains what I'm trying to do. I'm effectively trying to decide the class to use at runtime?

Thank
Kieran
Jul 21 '05 #3
Ok, that explains at least what you want to do: You can use
Activator.CreateInstance("name-of-your-assembly", "layout1").Unwrap(), to
create an instance of a class by its name.

However, the more "type-safe" approach would be something like:

Type myClass = typeof(layout1);
....
Table myTable = Activator.CreateInstance(myClass);

Or you could implement IClonable in all your classes, and write:

ICloneable myClass = new layout1;
....
Table myTable = myClass.Clone();

(I think this one is GoF pattern, but don't remember it's name)

Niki

"Kieran" <an*******@discussions.microsoft.com> wrote in
news:67**********************************@microsof t.com...
Hi,

Thanks for your reply, I was hoping though to feed in the class name though, e.g
string myClass = 'layout1'

Table myTable = new myClass

I know the above wont work but I hope this explains what I'm trying to do. I'm effectively trying to decide the class to use at runtime?.
Thanks
Kieran

Jul 21 '05 #4

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

Similar topics

2
by: Timothy Stark | last post by:
Hello folks, I am working on my program and was trying to implement 'dynamic' classes by using virtual function calls but it did not work. I want to convert from 'class test1' to 'class test2'...
0
by: Shailesh | last post by:
If I'm not mistaken, C++ doesn't have support for dynamic class members. I'm considering if such a facility would be useful, and what method would make a good workaround. I have a generic...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
7
by: Mike Livenspargar | last post by:
We have an application converted from v1.1 Framework to v2.0. The executable references a class library which in turn has a web reference. The web reference 'URL Behavior' is set to dynamic. We...
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
12
blackstormdragon
by: blackstormdragon | last post by:
Im having trouble with my classList variable. It's a dynamic array of strings used to store the names of the classes(my program ask for students name, number of classes, then a list of the classes). ...
5
by: Guillermo Schwarz | last post by:
C++ers, I have programmed in C++ since 1991 and I probably created my best abstraction layers in C++ in those days. Since 2001 I've been programming in Java (at first against my will, then I...
2
by: doomer | last post by:
Hello, I'm trying to build a set of classes that act as the handlers for a simple expression parser, and i'm wondering how to preserve the dynamic type information from derived classes. An...
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
5
by: bearophileHUGS | last post by:
I often use Python to write small programs, in the range of 50-500 lines of code. For example to process some bioinformatics data, perform some data munging, to apply a randomized optimization...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.