Hi,
[color=blue]
> I don't know of anything that works like virtual function templates, and I
> expect if there was such a thing, it would be troublesome enough to[/color]
dominate[color=blue]
> your entire program. It is more likely you should put other design[/color]
elements[color=blue]
> on the table.[/color]
ok... from Stephen Love I got the following link which implements "something
like virtual function templates":
http://www.slove.pwp.blueyonder.co.u...of_idioms.html
But sadly at the moment I dont know how to use it in my case.
[color=blue]
> I think it will be very hard to give you any advice without knowing what[/color]
the[color=blue]
> purpose of your design is. So, you claim Command must be a template[/color]
class.[color=blue]
> Why did you choose a template class for Command? For how many different
> types would it be reasonable to instantiate Command? What is a "Command"
> and what does it need to do?[/color]
So my basic problem is that I wanna implement the chain of responsibility
pattern. In my case the Instruments are the elments of the chain. Now I have
something lika a processor which creates Command-Objects. These Command
objects should be handled by the Instruments handle_command function. If one
Instrument "think" it is responsible for that command it will process it
further. Otherwise it will call the handle_command function of the
successor. For me it would be much better when the Command-class would be a
class template, cause the types used in the Command are supposed to be
different. What I mean with that is, that is could be possible that there
will be Commands with other data-types in it, and that's the problem why I
think I need something like virtual function templates.
[color=blue]
> I'm especially worried about your Command template because you gave an
> example of Command <float, 1.0>, which is questionable practice even were[/color]
it[color=blue]
> standard. Now, the compiler may or may not let Command <float,[/color]
1.00000000>[color=blue]
> and Command <float, 1.00000001> be the same type. The second parameter
> should probably be a constant member instead.[/color]
Why the Compiler may or may not let Command <float, 1.00000000>
and Command <float, 1.00000001> be the same type?
[color=blue]
>
> If all Commands are of numeric types, why not just use a double?
> Instantiating for different types might confuse the design issues.[/color]
No some commands will use for example unsigned char, others strings, and so
on.
[color=blue]
> Also, you have stated that handle_command must be virtual. Why? What[/color]
does[color=blue]
> it do? "Handle_command" is so general it sounds like you are avoiding
> making design decisions about things that can be done with commands - why[/color]
is[color=blue]
> this necessary? What is an "Instrument"?[/color]
The handle_command function will process the data, which is in the Command,
but only if it thinks that it is responsible for that Command, otherwise it
will send it to the next instrument. An Instrument could for example be a
speed-instrument, which measures the speed of a car. Always when the speed
of the car change, the processor will send a Speed-Command which then has to
be processed by the correct instrument.
The whole thing is not that easy, so the fact that there is a chain of
responisbility and a processor makes sense ( at least for me ), cause all
instrument are connected to a serial bus. So they send there data on that
serial bus one after another to a queue, where the processor then goes and
reads the next record to transform it to a command and send it to the chain.
I hope that makes things a bit more clear.
[color=blue]
> Hope we can figure something out.[/color]
That would be really cool.
Bye and thanks,
Sebastian