|
Boost Users : |
From: Wu Yinghui, Freddie (yhwu_at_[hidden])
Date: 2006-10-26 10:08:38
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
> Wu Yinghui, Freddie wrote:
>
> [snip]
>
>>
>> The situation is like this: In the pseudo-code you provided, DoWork()
>> function is declared in the Base class, and is overridden by Derived1
>> and Derived2, with a fixed number of arguments. My problems is that,
>> my base class cannot predict the exact number of parameters that a
>> derived class may have. (A derived class may have 10 parameters,
>> while another may have none.) So it looks a little bit out-of-shape
>> in terms of the OO programming style I'm familiar with if I'm going
>> to provide overloads of DoWork() for all the possible parameters used
>> by all derived classes (not to mention the undesirable dependency
>> introduced).
>
> In order to know which parameters to send through the interface, you'll
> have to know the exact subclass? Sorry, that doesn't make sense.
>
> What's the real problem you are trying to solve - could Boost.Variant +
> static_visitor (or some other variant on the Visitor pattern) help?
>
> / Johan
My situation is like this:
I have a class hierarchy briefly shown as below (assuming virtual member
function template is allowed, just to demonstrate the idea):
===== CODE =====
class Base
{
//...
// This is the function that makes use of Boost.Parameter
template <typename ArgumentPack>
virtual void Configure(ArgumentPack const &arguments) = 0;
};
// This class resides in Derived1.dll
class Derived1 : public Base
{
template <typename ArgumentPack>
void Configure(ArgumentPack const &arguments)
{
//...
}
};
// This class resides in Derived2.dll
class Derived2 : public Base
{
template <typename ArgumentPack>
void Configure(ArgumentPack const &arguments)
{
//...
}
};
===== CODE =====
To use the class hierarchy, my program loads the DLL requested by user
using LoadLibrary() (We're using Windows, but it should be similar to
Linux, I suppose), and makes use of the Derived1/Derived2 classes via a
pointer to the Base class.
Since I have no information about the derived classes when building my
main executable (only Base class is known then), I cannot make direct
use of Derived1/Derived2 types in my main program. -- Yet, I need a way
to provide some arbitrary set of arguments to the derived classes.
Hope my explanation clears your doubts. Do you have any suggestion or
alternative design in mind?
Cheers,
Freddie
- --
Wu Yinghui, Freddie
Research & Development
Senior Software Engineer
Volume Interactions Pte Ltd
1 Kim Seng Promenade, #12-01
Great World City East Tower
Singapore 237994
Tel: +65 62226962 (Ext 216)
Fax: +65 62226215
Email: yhwu_at_[hidden]
URL: http://www.volumeinteractions.com
Important: This message is intended for the recipient(s) addressed
above. It contains privileged and confidential information. If you are
not the intended recipient, please notify the sender immediately by
replying to this message and then delete it from your system. You must
not read, copy, use, or disseminate this communication in any form.
Thank you.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
iD8DBQFFQMFlIgDxhB4QTtMRA5JAAJ0fxjjw9IOlBOr+m2ccXD5d0Sh1EwCeKSJs
/NhscTXToOeUpTgwsNBNkr8=
=Kb9r
-----END PGP SIGNATURE-----
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net