Is the following so-called "delegation "? If not how to make some changes so
that the F class delegates its operation to an E instance.
On the other hand the following code runs without any problem. Is there any
potential problems with it?
class E
{
public:
void Draw_E(int a, int b) { cout << "Draw in E " << a*b<< endl; }
};
class F
{
E *e;
public:
void Draw_F() { e->Draw_E( 123, 456 ); cout << "Draw in F" << endl; }
};
int main(void){
F f;
f.Draw_F();
return 0;
} 6 4424
> Is the following so-called "delegation "?
Yep. If not how to make some changes so that the F class delegates its operation to an E instance.
Delegation has no direct language support, so you "just do it".
Delegation means that users of F are unaware that a secret E performed
Draw_F.
On the other hand the following code runs without any problem. Is there
any potential problems with it?
Delegation is good if users of F generally remain unaware of all Es in the
program. This is an example of "decoupling ".
Delegation is bad if F has no other reason to exist, or if users of F could
have used E and simplified the program. Maybe F should be unaware of E.
--
Phlip http://www.c2.com/cgi/wiki?TestFirstUserInterfaces
Phlip <ph*******@yaho o.com> wrote in message
news:pj******** *********@newss vr32.news.prodi gy.com... Is the following so-called "delegation "? Yep.
If not how to make some changes so that the F class delegates its operation to an E instance.
Delegation has no direct language support, so you "just do it".
Delegation means that users of F are unaware that a secret E performed Draw_F.
On the other hand the following code runs without any problem. Is there any potential problems with it?
Delegation is good if users of F generally remain unaware of all Es in the program. This is an example of "decoupling ".
Delegation is bad if F has no other reason to exist, or if users of F
could have used E and simplified the program. Maybe F should be unaware of E.
-- Phlip http://www.c2.com/cgi/wiki?TestFirstUserInterfaces
Thank you very much!
Notice that in class F, there's no instance of class E, but a pointer. Then
inside Draw_F() function Draw_E() is called with a statement "e->Draw_E."
Is this good way to do delegation? Is this good coding in C++ in general?
<DPfan> Is the following so-called "delegation "? If not how to make some changes so that the F class delegates its operation to an E instance.
On the other hand the following code runs without any problem. Is there any potential problems with it?
class E { public: void Draw_E(int a, int b) { cout << "Draw in E " << a*b<< endl; } };
class F { E *e; public: void Draw_F() { e->Draw_E( 123, 456 ); cout << "Draw in F" << endl; } };
int main(void){ F f; f.Draw_F(); return 0; }
</>
I wonder why it does run correct. Possibly luck. The
object pointed to by E*e is never created. I added
a constructor and a destructor.
-X
#include<iostre am>
class E
{
public:
void Draw_E(int a, int b) { cout << "Draw in E " << a*b<< endl; }
};
class F
{
E *e;
public:
F():e(new E){}
virtual~F(){del ete e;}
void Draw_F() { e->Draw_E( 123, 456 ); cout << "Draw in F" << endl; }
};
int main(void){
F f;
f.Draw_F();
return 0;
}
> > Delegation is good if users of F generally remain unaware of all Es in
the program. This is an example of "decoupling ".
Delegation is bad if F has no other reason to exist, or if users of F could have used E and simplified the program. Maybe F should be unaware of E.
Notice that in class F, there's no instance of class E, but a pointer.
Then inside Draw_F() function Draw_E() is called with a statement "e->Draw_E." Is this good way to do delegation? Is this good coding in C++ in general?
No. Always use the simplest and weakest thing.
Agent Mulder pointed out you had no E instance, so he added 'new'.
You could also fix that by removing the *, and replacing the -> with a dot .
In terms of OO design theory, delegation does not require *, or . ; only
that F know an E ready for the job. "Know" means "can access".
In terms of program stability, don't point without overwhelming need. Prefer
actual things, and pass them by reference. Don't point to character arrays -
use std::string. Don't point to arrays - use std::list or std::vector.
So your simplest delegation lets F have a member of type E.
--
Phlip
> Notice that in class F, there's no instance of class E, but a pointer. Then inside Draw_F() function Draw_E() is called with a statement "e->Draw_E." Is this good way to do delegation? Is this good coding in C++ in general?
The main advantage of delegation is that you can reduce the dependencies.
In this example, you can get by without including the header file
for E within F if the implemntation of the delegating function is placed
in the CPP file.
See the following article for decoupling of header files: http://www.eventhelix.com/RealtimeMa...dePatterns.htm
Sandeep
-- http://www.EventHelix.com/EventStudio
EventStudio 2.0 - Generate Sequence Diagrams and Use Cases in PDF
> The main advantage of delegation is that you can reduce the dependencies. In this example, you can get by without including the header file for E within F if the implemntation of the delegating function is placed in the CPP file.
Per "always use the simplest and weakest thing", then if you have more than
one user of E, or if E's header requirements are more complex than F's, you
may benefit from putting E in a different header from F's, and
forward-declaring it in F's header.
However, if nobody else uses Es without Fs, you may lose the benefits of
putting it in a separate header.
Organically, as E grows the pressures increase to remove its dependencies
from F's. But as E shrinks pressures increase to put it inside F's header,
or inside F, or even inside F's implementation file.
See the following article for decoupling of header files:
/Large Scale C++ Software Design/ and /Exceptional C++/.
--
Phlip http://www.c2.com/cgi/wiki?TestFirstUserInterfaces This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rene Pijlman |
last post by:
Section 6.5 "What is delegation?" of the FAQ says:
"Python programmers can easily implement delegation. For example, the
following class implements a class that behaves like a file but converts
all written data to uppercase:
class UpperOut:
def __init__(self, outfile):
self.__outfile = outfile
def write(self, s):
|
by: Jacob |
last post by:
Hello All,
I am trying to serve out some content via IIS that is hosted on a
remote fileserver, and am unable to get the delegation working
correctly. Our setup is as follows:
Local LAN
Windows 2000 domain (mixed-mode): MYDOMAIN (mydomain.net)
Windows 2003 Server w/IIS6: WEB01
Windows 2000 Server hosting files: FILE01
Windows XP Pro client workstation: CLIENT01
|
by: Tony Johansson |
last post by:
Hello!
What does it mean with delegation and can you give me one example.
//Tony
|
by: |
last post by:
Hi,
I am working on a n-tier app using remoting. I am using the VS 2005 beta
2. My server needs to access a remote resources on behalf on the connected
user.
I have configured my server like :
<channel ref="tcp" secure="true" port="8081" impersonate="true">
and my client:
<channel ref="tcp" port="0" secure="true"
|
by: russell.lane |
last post by:
I'm building out a pretty standard n-tier web application. The stack
includes application/presentation, biz logic, and data access layers on top
of an SQL server back end.
We want to use impersonation and delegation to forward the user's Windows
login through all layers in the stack. To support this, I'm setting up a
set of domain accounts which we use to create SPNs for the various services
in the various layers.
At this point, I'm...
| |
by: JimLad |
last post by:
In advance, sorry if this is the wrong group...
SQL Server 2000 SP3 on Server 2003. SQL Account and Computer both
Trusted for Delegation. Given SPN.
IIS 5.0 on W2000. Kerberos enabled. Computer Trusted for Delegation.
Integrated Windows Authentication selected. Medium pooled. Not the
default website - using IP address to connect from client.
IWAN_<computernamelocal account is running as part of operating
system and trusted for...
|
by: Marc Castrechini |
last post by:
This is a classic double hop delegation issue, however its the first time we
are setting this up so we are doing something incorrectly. If we run
through the IDE or using a localhost path on the web server the command
succeeds. However, if we use the servername or ip through IIS it fails.
For this reason we know we have permissions setup correctly on the file
server.
Can anyone identify what we could possibly be doing wrong here:
...
|
by: Patrick |
last post by:
Hello
I have the following scenario
- SQL 2005 server (serversql)
- Windows 2003 with IIS (serveriis)
- Windows 2003 ADS (serverads)
I want to connect to an intranet application using NTML with impersonation
and delegation. so for this I made the following change in web.config
<identity impersonate="true"/>
|
by: =?Utf-8?B?TWF5ZXI=?= |
last post by:
Hi,
I'm using two form classes and I would like all methods of the second class
(the child class) to be managed by the first class (the main class).
Is delegation the best solution for me?
If so, how can I define delegation?
--
Thanks,
Mayer
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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: 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...
|
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: 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();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |