/*
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(){retur n Mean;}
double getVariates(){
Variate = function(Mean,S d);
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.Variat e;
// Ideally, I would then like to have a form of dependence, which
// makes that everytime I call:
X = RanVar_B.getVar iates();
// the corresponding Mu in RanVar_A is also updated. So calling,
Y = RanVar_A.getVar iates();
// 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
*/
3 1946
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.
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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!
|
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:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsmtps/html/writingmngsinks.asp). I
set my project properties as 'Register as COM interop' to true, I can
install it my project on my developement machine without a flaw. Great.
|
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 the way I expected to write an tiered
application is tight-coupled and should be written loosely coupled..........
I am kind of new to multi-tier application programming, although I have good
experience of classes, and objects.
|
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 layer, and the business
layer is coupled to the data layer. So far so good.
Suppose the data layer raises an event, and it passes Me (the sender) as an
object, and e (MyEventArgs, a descendent of EventArgs) to the layer above
(the business...
|
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 Common, Object and Dat modules are not signed DAAB
runs OK but as soon as I sign them I get the following error:
**********************************************************************
| |
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 installed into the GAC.
We originally had this assembly without a strong-name and we were
successfully using it by referencing it when it was NOT in the GAC. The
assembly was built using the 1.0 framework and we were able to call it from
both 1.0...
|
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 dll into a console application (f.x
StrongConsoleApp.exe) and run it if I have somehow specified the public
part of the strong key and not otherwise.
|
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 in severel 'underwater operations'
* there is a list which stores objects of class B
There are several issues I'm not sure about:
|
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 since I've
installed so many versions of Visual Studio)
RL
http://msdn.microsoft.com/en-us/library/h4fa028b.aspx
Deployment in Visual Studio
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |