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

Registering sub-classes to a central location

7
Here is an interesting problem I've come across. It's more on the use of some C++ design patterns.

Scenario: There is an interface. Sub-classes implement this interface. There is a manager that should iterate through these sub-classes and issue commands, etc.

Problem: How is it possible to register these sub-classes to the manager at compile time?

I have tried doing something like:

Expand|Select|Wrap|Line Numbers
  1. typedef struct List {
  2.     Interface * subclass;
  3. } List;
  4. List classes[] = {
  5.     new Subclass1();
  6.     new Subclass2();
  7. };
  8.  
and let the manager iterate through classes. However, this means the manager will have no control over which subclass gets loaded into memory. How is possible to address a class without instantiating it? I realize this is kind of like reflective programming, and I don't mind templates in this case.

Thanks.
Jan 22 '09 #1
5 1404
Banfa
9,065 Expert Mod 8TB
Why would you need to register these class with the manager, surely the manager can just access them through the interface class.
Jan 22 '09 #2
MTsoul
7
The question is how? The interface is great if I have an object of the subclass, in which case the manager can manipulate the object with the interface. How do I address the subclass if no objects have been created?

Code execution starts from the manager, which should then instantiate a bunch of subclasses (through the interface or some other mechanism). How can this be done without statically instantiating the subclasses like the code in the first post?
Jan 22 '09 #3
Banfa
9,065 Expert Mod 8TB
I think you may wish to look up the factory design pattern which does this sort of thing.
Jan 22 '09 #4
MTsoul
7
Thanks. I thought about that but decided to go with function pointers. Factory classes have the same problem as the one I described. I still need to instantiate the Factory classes to make new objects. Function pointers take care of that problem I think.
Jan 22 '09 #5
weaknessforcats
9,208 Expert Mod 8TB
How is possible to address a class without instantiating it? I realize this is kind of like reflective programming,
You can't. Unless there's an object there's no address and there's no object until your code executes. Ergo, nothing can be done at compile time.

Do as Banfa suggests and create a Factory. Your factory object cna be created on the heap and after it creates and registers your objects, it can be deleted.
Jan 23 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bob | last post by:
Hi, I am having trouble registering a row from a mysql query so far I have the mysql part working : while ( $val = mysql_fetch_array( $result )) { print("<tr><td>$val</td> <td>$val</td>...
6
by: Daniel Bass | last post by:
The scenario: ------------- I've created a simple COM object according to a tutorial I found: http://www.csharphelp.com/archives/archive281.html It automatically creates a Type Library...
2
by: glenn | last post by:
I have written a COM Server in C# and its working perfectly. I am not ready to deploy to client computers to begin the real testing and am now wondering how to perform. The part that confuses me...
10
by: Sylvain Audet | last post by:
Hello! We have a Windows application that is using Crystal Reports reports containing Barcode fonts. Those reports are called through reflection into a Crystal Report Viewer and we need to have...
13
by: noone | last post by:
consider the following problem: You have a C style library and API that uses callbacks to implement functionality. Examples of this are X11 API, OpenGL/GLUT...The List goes on. The power of...
1
by: shivkumar2004 | last post by:
Hi!, I am developing a chat system using vb.net in vs 2005. I am getting the following error while registering the events. error details: System.InvalidOperationException was unhandled...
0
by: shivkumar2004 | last post by:
Hi, I m getting the following error while registering the events on client appl. error: "An error occurred creating the form. See Exception.InnerException for details. The error is: Exception...
2
by: linuxfedora | last post by:
I have written a C# program which has an activeX control (abc.ocx) in Visual Studio 2005, and used the setup and deployment project to create an setup.exe and setup.msi that act as an installer. ...
0
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via...
1
by: Bryan | last post by:
A Person can belong to one group. I want to be able to set the group using these two methods: PersonA.Group = GroupA or GroupA.Add(PersonA) In the Set method of Person.Group, the Person...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.