0

How would you model a USB cable using interfaces so that the cable itself is unidirectional(different jacks) but in theory I could connect the "output" side to the "input" side but not input to input.

e.g., I'm trying to model the following

* -> + -> * -> + etc...

but never have something like * -> * -> ... or + -> + -> ...

but each * and + is basically interchangeable. I just want to make sure *'s go through the -> processes before they are allowed to be used again.

The idea is pretty simple, outputs can be used as inputs BUT inputs can be used as outputs... but inputs and outputs are pretty much interchangable data wise(just a stream of data).

(it seems I have to use an adapter pattern but I'd like to somehow use the composite pattern so I don't have to explicitly adapt anything. I'd like it just to work plug and play and have the appropriate connection chosen)

e.g.,

interface data;
interface input : data;
interface output : data; 

this allows inputs to go to inputs or outputs.

4

1 回答 1

0

也许您可以使用(C# 语法)如下结构:

class Input
{
    Output output;
}
class Output
{
    Input input;
}

然后一个链input -> output -> input可能看起来像:

Input input1 = new Input();
Output output2 = new Output();
Input input3 = new Input();
output2.input = input1;
input3.output = output2;
于 2013-07-03T21:46:01.590 回答