【问题标题】:Model usb cable with interfaces带接口的模型usb电缆
【发布时间】:2013-07-03 21:07:02
【问题描述】:

您如何使用接口对 USB 电缆进行建模,以便电缆本身是单向的(不同的插孔),但理论上我可以将“输出”端连接到“输入”端,但不能将输入端连接到输入端。

例如,我正在尝试对以下内容进行建模

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

但从来没有像 * -> * -> ... 或 + -> + -> ...

但是每个 * 和 + 基本上是可以互换的。我只是想确保 * 在被允许再次使用之前通过 -> 进程。

这个想法很简单,输出可以用作输入,但输入可以用作输出......但是输入和输出在数据方面几乎可以互换(只是数据流)。

(似乎我必须使用适配器模式,但我想以某种方式使用复合模式,所以我不必明确调整任何东西。我希望它只是即插即用并具有适当的选择的连接)

例如,

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

这允许输入转到输入或输出。

【问题讨论】:

    标签: oop interface


    【解决方案1】:

    也许您可以使用(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;
    

    【讨论】:

      猜你喜欢
      • 2016-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-04
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多