473,373 Members | 1,415 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,373 software developers and data experts.

Communication between classes

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!
Jul 19 '05 #1
2 4856

"<- 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


Jul 19 '05 #2
> > 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?
Jul 19 '05 #3

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

Similar topics

9
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...
1
by: Ayende Rahien | last post by:
Is it possible to use events as a communication mechanism between threads?
1
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. ...
4
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...
2
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...
1
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...
2
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...
21
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...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: 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...

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.