473,738 Members | 3,636 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class Design Alternatives

Hi,

This is from a typical telecom software implementation. I have three
subsystems (x, y, z) which exchange data amongst them. The arrangement
is such that x talks to y over interface xy. y subsystem them talks to
z over yz interface. In a typical scenario, y would receive a set of
parameters from x (over xy). Some of these are meant for z subsys as
well. So y needs to send these plus some more parameters to z.

The implementation options for this kind of arrangement can be :
1. Define separate classes (with access methods for each of the
individual parameters) at each xy and yz interface. Let the common
subsys layer (here y subsys) copy the relevant parameters from x to
that on the interface with z. The problem here is overhead of copy
operation that can be expensive spl. for telecom s/w case.

2. Other option is to define a class that has get/set methods for all
parameters (xy + yz) and let each individual subsystem class (x/y/z)
call the relevant methods. The problem here is z has access to member
functions which are not even relevant to it.

Are there any better arrangements possible ? Can i have something like
restricted access to member functions by different user classes (like
z have only the relevant methods visible from option 2 above).

thanks
-Sj
Dec 20 '07 #1
4 1287
On 2007-12-20 19:42, sunderjs wrote:
Hi,

This is from a typical telecom software implementation. I have three
subsystems (x, y, z) which exchange data amongst them. The arrangement
is such that x talks to y over interface xy. y subsystem them talks to
z over yz interface. In a typical scenario, y would receive a set of
parameters from x (over xy). Some of these are meant for z subsys as
well. So y needs to send these plus some more parameters to z.

The implementation options for this kind of arrangement can be :
1. Define separate classes (with access methods for each of the
individual parameters) at each xy and yz interface. Let the common
subsys layer (here y subsys) copy the relevant parameters from x to
that on the interface with z. The problem here is overhead of copy
operation that can be expensive spl. for telecom s/w case.

2. Other option is to define a class that has get/set methods for all
parameters (xy + yz) and let each individual subsystem class (x/y/z)
call the relevant methods. The problem here is z has access to member
functions which are not even relevant to it.

Are there any better arrangements possible ? Can i have something like
restricted access to member functions by different user classes (like
z have only the relevant methods visible from option 2 above).
You could make y a friend of the class containing the data, y would then
be able to access private methods of the data class but z will not. Be
aware though that y will have access to all private members of the data
class, which might not be desirable. Example:

class data
{
void foo() const { }
public:
void bar() const { }
friend struct A;
};

struct A
{
void doit(const data& d)
{
d.foo();
d.bar();
}
};

struct B
{
void doit(const data& d)
{
//d.foo();
d.bar();
}
};
int main()
{
data d;
A a;
B b;
a.doit(d);
b.doit(d);
}

In the above example B can not use the foo() function because it is
private, but A is a friend of data and can thus access it.

Another possibility is to use sub-classing, let z work with a data-class
that have the functions that z needs, and then create a subclass that
adds those functions that y needs, then let z work on the base-class and
y on the derived class. If you need to copy the data-class beware of
slicing. Example:

struct data
{
void bar() const { }
};

struct data2 : public data
{
void foo() const { }
};

struct A
{
void doit(const data2& d) // OBS, data2
{
d.foo();
d.bar();
}
};

struct B
{
void doit(const data& d) // OBS, data
{
//d.foo();
d.bar();
}
};
int main()
{
data2 d; // OBS, data2
A a;
B b;
a.doit(d);
b.doit(d);
}

Since B works on data which does not have the foo() function it can not
call it, while A works on the derived data2 which does have foo(). If
all the data-members are declared in the base-class you should be able
to cast between the two as needed.

--
Erik Wikström
Dec 20 '07 #2
On Dec 20, 7:42 pm, sunderjs <sunde...@gmail .comwrote:
This is from a typical telecom software implementation. I have three
subsystems (x, y, z) which exchange data amongst them. The arrangement
is such that x talks to y over interface xy. y subsystem them talks to
z over yz interface. In a typical scenario, y would receive a set of
parameters from x (over xy). Some of these are meant for z subsys as
well. So y needs to send these plus some more parameters to z.
The implementation options for this kind of arrangement can be :
1. Define separate classes (with access methods for each of the
individual parameters) at each xy and yz interface. Let the common
subsys layer (here y subsys) copy the relevant parameters from x to
that on the interface with z. The problem here is overhead of copy
operation that can be expensive spl. for telecom s/w case.
2. Other option is to define a class that has get/set methods for all
parameters (xy + yz) and let each individual subsystem class (x/y/z)
call the relevant methods. The problem here is z has access to member
functions which are not even relevant to it.
The xy and yz are separate interfaces. That should answer the
question at the design level. And I don't see where that would
necessitate a copy: the xy interface object could easily contain
a yz interface object, or a pointer to one, and that object can
be passed on to z without copy (providing lifetimes are
sufficient).

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Dec 21 '07 #3
On Dec 21, 3:48*pm, James Kanze <james.ka...@gm ail.comwrote:
On Dec 20, 7:42 pm, sunderjs <sunde...@gmail .comwrote:


This is from a typical telecom software implementation. I have three
subsystems (x, y, z) which exchange data amongst them. The arrangement
is such that x talks to y over interface xy. y subsystem them talks to
z over yz interface. In a typical scenario, y would receive a set of
parameters from x (over xy). Some of these are meant for z subsys as
well. So y needs to send these plus some more parameters to z.
The implementation options for this kind of arrangement can be :
1. Define separate classes (with access methods for each of the
individual parameters) at each xy and yz interface. Let the common
subsys layer (here y subsys) copy the relevant parameters from x to
that on the interface with z. The problem here is overhead of copy
operation that can be expensive spl. for telecom s/w case.
2. Other option is to define a class that has get/set methods for all
parameters (xy + yz) and let each individual subsystem class (x/y/z)
call the relevant methods. The problem here is z has access to member
functions which are not even relevant to it.

The xy and yz are separate interfaces. *That should answer the
question at the design level. *And I don't see where that would
necessitate a copy: the xy interface object could easily contain
a yz interface object, or a pointer to one, and that object can
be passed on to z without copy (providing lifetimes are
sufficient).

--
James Kanze (GABI Software) * * * * * * email:james.ka. ..@gmail.com
Conseils en informatique orientée objet/
* * * * * * * * * *Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34- Hide quoted text -

- Show quoted text -
As mentioned in the problem text, some of the parameters from xy
interface object needs to be passed to yz interface object. One
obvious way is to copy these from xy to yz object. To avoid it one can
form a superset object containing xy + yz parameters. But then as per
the design, access to this superset object should be restricted to
each of the interfaces. Defining a base class interfaces for xy and yz
and then deriving a class from these seems a better option.

Something like:

class common
{
public:
virtual void getA() = 0;
virtual void setA() = 0;
};

class xy:public common
{
public:
virtual void getB() = 0;
virtual void setB() = 0;
};

class yz:public common
{
public:
virtual void getC() = 0;
virtual void setC() = 0;
};

//define a superset class derived from xy & yz
//shall contain all data elements
class totalSet:public xy, public yz
{
..
};

//subsystem class
class X
{

};
int main()
{

}

Dec 21 '07 #4
On Dec 21, 3:48*pm, James Kanze <james.ka...@gm ail.comwrote:
On Dec 20, 7:42 pm, sunderjs <sunde...@gmail .comwrote:


This is from a typical telecom software implementation. I have three
subsystems (x, y, z) which exchange data amongst them. The arrangement
is such that x talks to y over interface xy. y subsystem them talks to
z over yz interface. In a typical scenario, y would receive a set of
parameters from x (over xy). Some of these are meant for z subsys as
well. So y needs to send these plus some more parameters to z.
The implementation options for this kind of arrangement can be :
1. Define separate classes (with access methods for each of the
individual parameters) at each xy and yz interface. Let the common
subsys layer (here y subsys) copy the relevant parameters from x to
that on the interface with z. The problem here is overhead of copy
operation that can be expensive spl. for telecom s/w case.
2. Other option is to define aclassthat has get/set methods for all
parameters (xy + yz) and let each individual subsystemclass( x/y/z)
call the relevant methods. The problem here is z has access to member
functions which are not even relevant to it.

The xy and yz are separate interfaces. *That should answer the
question at thedesignlevel. *And I don't see where that would
necessitate a copy: the xy interface object could easily contain
a yz interface object, or a pointer to one, and that object can
be passed on to z without copy (providing lifetimes are
sufficient).

--
James Kanze (GABI Software) * * * * * * email:james.ka. ..@gmail.com
Conseils en informatique orientée objet/
* * * * * * * * * *Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34- Hide quoted text -

- Show quoted text -
As mentioned in the problem text, some of the parameters from xy
interface object needs to be passed to yz interface object. One
obvious way is to copy these from xy to yz object. To avoid it one
can
form a superset object containing xy + yz parameters. But then as per
the design, access to this superset object should be restricted to
each of the interfaces. Defining a base class interfaces for xy and
yz
and then deriving a class from these seems a better option.

Something like:
class common
{
public:
virtual void getA() = 0;
virtual void setA() = 0;

};
class xy:public common
{
public:
virtual void getB() = 0;
virtual void setB() = 0;
};
class yz:public common
{
public:
virtual void getC() = 0;
virtual void setC() = 0;
};
//define a superset class derived from xy & yz
//shall contain all data elements
class totalSet:public xy, public yz
{
//contain implementation of the interfaces
};
//subsystem class
class X
{
void doSomething(xy& obj1)
{
obj1.setA();
obj1.setC(); //Error: can't access
}

};

class Z
{
void doSomething(yz& obj2)
{
obj2.getA(); //permissible
obj2.setB(); //Error:can't access
}
};

int main()
{
totalset t1;
Z z;
X x;

x.doSomething(t 1); //only xy interface exposed
z.doSomething(t 1); //only yz interface exposed
}
Dec 21 '07 #5

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

Similar topics

50
6362
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong def foo(self, data): self.attr1=data self.attr2.append(data) The initialization of attr1 is obviously OK, all instances of Father redefine it in the method foo. But the initialization of attr2 is wrong
2
1450
by: qazmlp | last post by:
I just noticed the following class design in a module. class testClass { public: static long utilFunc1() ; static long utilFunc2() ; static long utilFunc3() ; private: testClass(){}; ~testClass(){};
15
9074
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for the purpose of learning to work with C++. It therefore makes some sense for me to give the situation the amount of consideration presented below. To be quite honest, I'm amazed at the amount there is to say about such a seemingly simple...
7
4917
by: _iycrd | last post by:
Is there an easy way to pin a pointer that is a member of a class, and leave that pointer pinned for the duration of the class's existence? The pointer would presumably be pinned inside the class's constructor, but maintain the pin after exiting the constructor. The syntax, at least under C++/CLI, seems to require simultaneous declaration and pinning. Any way around that?
0
2508
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that don't work nearly as well as they should, even for analysts and power users. The reason they haven't reached the masses is because most of the tools are so difficult to use and reveal so little
4
1771
by: nw | last post by:
Hi, I was wondering if someone would be able to give me some comments on the following class structure, it feels to me as if there must be a better way, but I'm unsure what it is, perhaps I should be using multiple inheritance? Basically I have a pure virtual class called Body, this contains a number of integration algorithms which are applied to the Body. Generally only one integration algorithm will be used with a
5
1492
by: Harinezumi | last post by:
Hello, I have a base class Base with given member variables, getters and setters, but it doesn't do much on its own. Then there are functionalities (Func) which can use this base class's member functions to achieve some complex computation. I would like to design this class structure in a way that a derived of Base, Derived can have added functionality with the use of Funcs, without further programming. Here's what I thought would work:...
8
2375
by: Floortje | last post by:
Hi i have been struggeling with this question for quite some time now. I have some helper classes that handle images (upload an image, create thumbnails and show a imagelist), links (add link, edit link, show linklist), comments (add comment, show commentlist) etc. I do not need all this functionality on every page. Ideally I could just extend the controller like this
1
1462
by: Mike | last post by:
I have always been told that I should only get the data I need for each web page, so my quandary is set against that backgound. Let's say I have a User class with 10 properties. I have a private method that populates all of these properties with values from the database. However, I may only need to display two of the properties on a web page (name and last login time, for example). Coming from a pure ADO/ADO.NET background, where I...
0
8788
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9208
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8210
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.