I have this class
-------------
class Component {
/*class*/ Data *d;
/*class*/ Draw *a;
};
-------------
from "Component" derive classes like "TextBox", "Button", "Label", "ComboBox" etc
from "Draw" derive classes like "TextBoxDraw", "ButtonDraw", "LabelDraw", "ComboBoxDraw" etc
from "Data" derive classes like "TextBoxData", "ButtonData", "LabelData", "ComboBoxData" etc
class "Draw" (or any derived class) gets data from class "Data" (or corresponding derived class)
different derived classes may get different data but corresponding classes communicate with the same data.
Derived classes upcast because of "Data" & "Draw" in member list of "Component"
So, which is the better method for communication between 2 member classes?
My approach until now is a variable length argument list without variable type like this:
------------------------
Data::getMessage(int message, ...);
------------------------
But this approach is very unsafe
do you have any better ideas?
Thanks! 2 4861
"<- Chameleon ->" <ch******@hotmail.NOSPAM.com> wrote in message
news:bl**********@nic.grnet.gr... I have this class ------------- class Component { /*class*/ Data *d; /*class*/ Draw *a; }; ------------- from "Component" derive classes like "TextBox", "Button", "Label",
"ComboBox" etc from "Draw" derive classes like "TextBoxDraw", "ButtonDraw", "LabelDraw",
"ComboBoxDraw" etc from "Data" derive classes like "TextBoxData", "ButtonData", "LabelData",
"ComboBoxData" etc class "Draw" (or any derived class) gets data from class "Data" (or
corresponding derived class) different derived classes may get different data but corresponding classes
communicate with the same data. Derived classes upcast because of "Data" & "Draw" in member list of
"Component" So, which is the better method for communication between 2 member classes?
My approach until now is a variable length argument list without variable
type like this: ------------------------ Data::getMessage(int message, ...); ------------------------ But this approach is very unsafe
do you have any better ideas?
Thanks!
You are not being very clear about the structure you have. Can you post the
actual code?
If what you're trying to do is use base-class pointers to access derived
class membersm then that is handled automatically by using virtual functions
and overriding them in the derived classes, provided, when you actually
create the members (in your derived classes), that you create them as
instances of their appropriate derived classes. You declare the member
pointers as their base class pointers, but you create the instances as
derived class instances. Make sense?
-Howard
> > I have this class ------------- class Component { /*class*/ Data *d; /*class*/ Draw *a; }; ------------- from "Component" derive classes like "TextBox", "Button", "Label", "ComboBox" etc from "Draw" derive classes like "TextBoxDraw", "ButtonDraw", "LabelDraw", "ComboBoxDraw" etc from "Data" derive classes like "TextBoxData", "ButtonData", "LabelData", "ComboBoxData" etc class "Draw" (or any derived class) gets data from class "Data" (or
corresponding derived class) different derived classes may get different data but corresponding classes communicate with the same data. Derived classes upcast because of "Data" & "Draw" in member list of "Component" So, which is the better method for communication between 2 member classes?
My approach until now is a variable length argument list without variable
type like this: ------------------------ Data::getMessage(int message, ...); ------------------------ But this approach is very unsafe
do you have any better ideas?
Thanks!
You are not being very clear about the structure you have. Can you post the actual code?
If what you're trying to do is use base-class pointers to access derived class membersm then that is handled automatically by using virtual functions and overriding them in the derived classes, provided, when you actually create the members (in your derived classes), that you create them as instances of their appropriate derived classes. You declare the member pointers as their base class pointers, but you create the instances as derived class instances. Make sense?
Yes. Derived class DerivedData from class Data, can overide virtual void Data::getMessage(int &a). But DerivedData wants give
different data from int& (e.g. float&) DerivedData::getMessage(float &a). Corresponding derived class DerivedDraw from Draw can
handle correctly this data (float&) instead of Draw which can handle correctly data int&.
So, I believe approach like this is the best but unsafe: virtual void Data::getMessage(...)
do you have any better ideas?
If you dont understand again think this:
We have a ComboBox : public Component
TextComboData::getMessage returns an array of strings which is the ComboBox list.
ColorComboData::getMessage returns an array of colors which is the ComboBox list.
TextComboDraw::getMessage gets an array of strings which is the ComboBox list and draws it.
ColorComboDraw::getMessage gets an array of colors which is the ComboBox list and draws it.
Different derived classes communicate with completely different data. So, how can handle this in upcasting? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Harald Massa |
last post by:
Hello,
I have a group of Python programms which I want to teach to "talk to each
other".
All run on Windows, on the same computer or in the same intranet.
Security of communication is not an...
|
by: Ayende Rahien |
last post by:
Is it possible to use events as a communication mechanism between threads?
|
by: Christopher |
last post by:
I have a class FrameListener, that contains a method which loops
continually, if this method returns false then the application exits.
I have a class KeyListener, that gets input from the user.
...
|
by: Viper Venom |
last post by:
Dear All:
I am trying to write an application that consist 2 executables
1) Server.exe
2) Client.exe
I start the server.exe first and then start the two client exe by code and
kill both of...
|
by: Leonardo D'Ippolito |
last post by:
Hi!
I have two .NET win apps that need to communicate on a TCP/IP network.
'App A' must ask 'app B' if it's allowed to do some task, and 'app B'
must authorize or prohibit it.
How can I do...
|
by: Liu Guidong |
last post by:
Dear friends,
I have a question about the communication between C# and
C++.
Can anyone help me ??
I have written a C# dll fies named "TestFordll2.dll",as
fllow:
using System;
namespace...
|
by: Jim Shank |
last post by:
I am really trying to find the best OOP way of doing this. I have a
parent MDI form with multiple children and I am trying to communicate
variables between them. I have been able to successfully...
|
by: dast |
last post by:
Hi,
I'm having trouble letting my background thread tell my main thread what to
do.
I'm trying to tell my main thread to open a form, but when my background
thread ends, the form that I...
|
by: Tony |
last post by:
Hello!
This is the scenario that we want to implement.
Assume we have three computers called client1, client2 and client3 that must
be able to register
itself on server A. Meaning telling...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |