473,508 Members | 2,382 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 1275
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 objektorientierter Datenverarbeitung
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...@gmail.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 objektorientierter Datenverarbeitung
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...@gmail.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 objektorientierter Datenverarbeitung
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(t1); //only xy interface exposed
z.doSomething(t1); //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
6290
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...
2
1441
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(){};...
15
9032
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...
7
4885
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...
0
2492
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...
4
1755
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...
5
1482
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...
8
2343
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,...
1
1455
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...
0
7231
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
7133
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
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7066
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
5643
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
4724
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...
0
3214
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...
0
1568
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 ...
0
435
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...

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.