473,404 Members | 2,174 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,404 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 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


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...
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: 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?
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
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,...
0
isladogs
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...

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.