473,397 Members | 2,077 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,397 software developers and data experts.

Strong coupling: Object Dependencies

/*
Hello everyone,

I am trying to impose some strong coupling between different
objects. This, to a large extent, directly challenge the principle of
encapsulation in C++.

Note that the form of dependencies that I am trying to devise is
between instances of classes, not between classes themselves. Hence, I
have already looked into issues of multiple inheritance, friends and
aggregation, which is not what I want.

Ideally, the member class data within one object could be linked with
the member class data within another object, so that any modification
of the former will result in an updating of the latter.

My application is a statistical software. Below is an example of my
problem with two different classes. A crucial point is that such
strong coupling must be imposable by the user in the main program
only, without modifying or creating a new class for that purpose.

Code Example:
*/

// Classes of random variables:
class Norm
{
public:
int Variate;
int Mu;
int Sigma;

void getMu(){return Mu;}
double getVariates(){
Variate = function(Mu,Sig);
return Variate; }
}

class Gam
{
public:
int Variate;
int Mean;
int Sd;

void getMean(){return Mean;}
double getVariates(){
Variate = function(Mean,Sd);
return Variate; }
}


int main()
{
Norm RanVar_A;
Gam RanVar_B;
double X, Y;

// This is where I need some help to devise an *operator*,
// which would induce some dependencies between two member class
// data, so that updating one, would also update the other.
RanVar_A.Mu *operator* RanVar_B.Variate;

// Ideally, I would then like to have a form of dependence, which
// makes that everytime I call:
X = RanVar_B.getVariates();

// the corresponding Mu in RanVar_A is also updated. So calling,
Y = RanVar_A.getVariates();

// returns a value based computed from the new Mu given by RanVar_B.
return 0;
}

/*
The problem is that the two data that I am trying to associate
are out of scope of each other. I have considered an 'observer design
pattern' approach. However, the instantiation of a 'subject' class,
which, in my specific problem could be called a 'statistical
model' class, does not exactly suit my needs. I don't really want to
update all my objects at once, but simply one relationship at a time.

It seems to me that the problem could easily be resolved by ensuring
that all data in each object are fully public and accessible from
anywhere else, but I don't know how to create such an environment, and
it wouldn't be a viable solution.It seems to me that the problem could easily be resolved by ensuring
that all data in each object are fully public and accessible from
anywhere else, but I don't know how to create such an environment, and
it wouldn't be a viable solution.

Finally, I have also tried an approach where I am passing a pointer to
a data in the 'main' environment to the constructor of each Norm
class, but this has again failed to achieve what I am trying to do.

Any help, or advice is very much welcomed,


Cedric
*/
Aug 8 '07 #1
3 1926
weaknessforcats
9,208 Expert Mod 8TB
Ideally, the member class data within one object could be linked with
the member class data within another object, so that any modification
of the former will result in an updating of the latter.
You are attempting to re-create the Observer design pattern using another pattern called Mediator.

Check the book Design Patterns by Erich Fromm, et al. Addison-Wesley 1994.

Your answers are on page 293.
Aug 8 '07 #2
You are attempting to re-create the Observer design pattern using another pattern called Mediator.

Check the book Design Patterns by Erich Fromm, et al. Addison-Wesley 1994.

Your answers are on page 293.
Thanks for your reply,

So, do you recommend that I try to implement a mediator pattern design, then, rather than an observer pattern one?

Are you sure that this book is by Erich Fromm?
I can't really find anything corresponding to that description.
Thanks,

C
Aug 8 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
Check the book Design Patterns by Erich Fromm, et al. Addison-Wesley 1994.
Oops. I meant Erich Gamma. It's early here.

ISBN 0-201-63361-2.

The Observer implements the Notify() so you can let observers know when the data has changed. When there are many Observers, then you may want to use a Mediator to notify the correct observers.

A typical use is where a Person is a data member of a Vehicle as the owner and the Vehicle needs to notify the Registration application if the address of the Person was changed in order to mail notices to the owner at the new address.
Aug 8 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dover | last post by:
It has be often mentioned that the coupling among objects should be avoided. What're the major cases that objects are closed coupled? How to avoid such cases? Many thanks!
20
by: Razzie | last post by:
Hey all, I'm really going through a small hell right now - I've completely lost it :) I made a project, using two interop libraries from exchange (created them as in this msdn article:...
4
by: Alex Stevens | last post by:
Well, It's 4:10 on Friday Afternoon and I am now in a state of turmoil....... I've just spoken with a trainer (who's opinion would be in far higher regard than mine), and he's just told me that...
19
by: Charles Law | last post by:
Take a solution with a project hierarchy along the lines of an n-tier system, so that we have a data layer, business layer and presentation layer. The presentation layer is coupled to the business...
3
by: John Skinner | last post by:
I am using C# in VS2005 and trying to make use of the "Data Access Application Block" version 2 I have created a small test application that to do the testing. If my application and the...
1
by: Tim F | last post by:
Problem: I'm receiving the error "File or assembly name XXXXX or one of its dependencies, was not found." when trying to execute code in an assmebly that has both a strong-name and has been...
8
by: per9000 | last post by:
Dear readers, I have some problems with strong keys. What I want to do is basically this. A - create an application (f.x. strongHello.dll) with a strong key. B - import the functions of this...
14
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
6
by: raylopez99 | last post by:
Anybody use Strong Name Signing? I think this is used by default for Resource files, which is one reason perhaps I can't get my resource files to work (somehow the public key is messed up, perhaps...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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...
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
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,...
0
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
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...
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.