 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
mojtaba_danai@yahoo.com Guest
|
Posted: Sat Jul 01, 2006 6:18 am Post subject: Design issue.... |
|
|
Hi
I am trying to make a adapter program.
-There can be different kind of adapters, which each can take data from
one source.
-It should be possible to plugin the new adapter for a new source of
data.
-The adapters all make a common structure to give it to the connected
clients. (I have implemented this part).
-Each adapter uses a specific API to collect data from data source.
How the design of the adapter class should look like? Which design
pattern?
There should probably be a superclass for all adapters, right? But they
have different APIs, as I said before, and one of the adapters inherits
already from couple of data source API classes.
Thanks.
Regards
mojtaba
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
UvGroovy Guest
|
Posted: Sat Jul 01, 2006 10:56 pm Post subject: Re: Design issue.... |
|
|
If in understand correctly, this sounds like you seek an adapter with a
factory:
class Adapter {
public:
void* getConvertedDataFromSource();
};
class SpecificSourceAdapter : public Adapter {
public:
class AdapterHelper : public SourceAPICass {
};
};
void AdapterFactory{
// Method to use adapters, Use whenever you have a new source.
Adapter* getAdapter(string sourceType) {
.....
}
// Add an adapter to the factory (on main())
};
Now all there is left to do is to register the adapters to the factory
(A known problem).
mojtaba_danai (AT) yahoo (DOT) com wrote:
| Quote: | Hi
I am trying to make a adapter program.
-There can be different kind of adapters, which each can take data from
one source.
-It should be possible to plugin the new adapter for a new source of
data.
-The adapters all make a common structure to give it to the connected
clients. (I have implemented this part).
-Each adapter uses a specific API to collect data from data source.
How the design of the adapter class should look like? Which design
pattern?
There should probably be a superclass for all adapters, right? But they
have different APIs, as I said before, and one of the adapters inherits
already from couple of data source API classes.
Thanks.
Regards
mojtaba
|
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Carl Barron Guest
|
Posted: Sun Jul 02, 2006 5:12 pm Post subject: Re: Design issue.... |
|
|
mojtaba_danai (AT) yahoo (DOT) com <mojtaba_danai (AT) yahoo (DOT) com> wrote:
| Quote: | Hi
I am trying to make a adapter program.
-There can be different kind of adapters, which each can take data from
one source.
-It should be possible to plugin the new adapter for a new source of
data.
-The adapters all make a common structure to give it to the connected
clients. (I have implemented this part).
-Each adapter uses a specific API to collect data from data source.
How the design of the adapter class should look like? Which design
pattern?
There should probably be a superclass for all adapters, right? But they
have different APIs, as I said before, and one of the adapters inherits
already from couple of data source API classes.
You have a collection of reader/writers [devices] that read/write |
various data
to all or parts of a commonly used user defined type say Message.
You want your code to read or write these Messages via these
devices without the code knowing actual method the data is transferred.
Correct??
struct Message;
wtruct transfer_base
{
virtual void get(message &) = 0;
virtual void put(message &) = 0;
virtual ~transfer_bbase(){}
protected;
transfer_base(){}
};
we need concrete classes to use the various devices, since each
requires a reference to the device and specific instructions to
do the transfer, we can separeate the actual transfer functions from
the hoder of the device reference and the virtual functions get(),put().
/* Action is a struct with two static functions
static void get(somedevice &,Message &);
static void put(somedevice &,Nessage &);
*/
template <class Device,class Action>
class transfer:public transfer_base
{
Device &d;
pubilc:
transfer(Device &x):d(x);
void get(message &m) {Action::get(d,m);}
void put(message &m) {Action::put(d,m);}
};
for each device we have a struct
template <class D> struct DeviceAction;
template <> struct DeviceAction<device>
{
static void get(device_1 &d,Message &m);
static void put(device_1 &d,Message &m);
};
for instance
template <class D>
inline
std::auto_ptr<transfer_base> make_transfer(D &d);
{
return std::auto_ptr<transfer_base>(
new tranfer<D,DeviceAction<D> >(d)));
}
is a possible factory function.
only specific code is in the specializations of DeviceAction<D>
constaining static functions to get/put data to/from a Device, needa
writing to 'connect a Device' to your code.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|