5

どなたか下のグラフの意味を教えてください。

ここに画像の説明を入力

  1. PolicyLayer と PolicyServiceInterface の関係は何ですか?
  2. PolicyServiceInterface と MachanismLayer の関係は何ですか。

C# コードも大歓迎です。

UML は、Martin C. Robert 著、Martin Micah 2006 による C# の Agile Principles, Patterns, and Practices からのものであることに注意してください。

2011/6/2 15 追記

以下は同じ意味を持っていますか? 1) 一端に三角形がある実線 2) 一端に三角形がある破線

2011/6/3 1st追記

違いは何ですか: 1) 一方の端に矢印がある実線 2) 一方の端に矢印がある破線

サンプルの例と、以下のリンクの PersistentObject および ThirdPartyPersistentSet:

UML ヘルプ C# 設計原則

2011/6/3 2nd追加

PolicyLayer と PolicyServiceInterface の関係は次のようになります。

public class PolicyLayer

{
    private PolicyServiceInterface policyServiceInterface = new PolicyServiceInterfaceImplementation();
}

class PolicyServiceInterfaceImplementation:PolicyServiceInterface {}

それにかんする

4

2 に答える 2

7

1) PolicyLayer と PolicyServiceInterface の関係は何ですか

------> はAssociation(「知っている」)

協会
(ソース: sedris.org )

C# コード:

public interface PolicyServiceInterface { }

public class PolicyLayer
{
    private IPolicyServiceInterface _policyServiceInterface;
    // Constructor Assocation
    public PolicyLayer(IPolicyServiceInterface policyServiceInterface)
    {
        _policyServiceInterface = policyServiceInterface;
    }
}

2) PolicyServiceInterface と MachanismLayer の関係は何ですか。

-- -|> はRealization(「実装」)

実現

C# コード:

public interface PolicyServiceInterface { }

public class MachanismLayer : PolicyServiceInterface 

3) 以下は同じ意味ですか: 1) 一方の端に三角形がある実線 2) 一方の端に三角形がある破線?

いいえ、意味が異なります。

------|> はGeneralization(「継承」)

一般化

C# コード:

public class PolicyServiceInterface { } // could also be abstract

public class MachanismLayer : PolicyServiceInterface 

違いは何ですか: 1) 一方の端に矢印がある実線 2) 一方の端に矢印がある破線

-- -> is Dependency("uses a") 依存関係には、ローカル変数、パラメーター値、静的関数呼び出し、戻り値など、さまざまな形式があります。

依存

C# コード:

// Here Foo is dependent on Baz
// That is Foo - - -> Baz
public class Foo {
   public int DoSomething() { // A form of local variable dependency
       Baz x = new Baz();
       return x.GetInt();
   } 
}

構成と集計については、こちらの回答を参照してください。

于 2011-06-02T13:55:42.273 に答える
2

PolicyLayerはポリシーサービスインターフェイスを使用します(おそらく参照を保持します)MachanismLayerはPolicyServiceInterfaceを実装します

 public interface IPolicyServiceInterface
    {
        void DoSomething();
    }

    public class MachanismLayer : IPolicyServiceInterface
    {
        public void DoSomething()
        {
            Console.WriteLine("MachanismLayer Do Something");
        }
    }

    public class PolicyLayer
    {
        private IPolicyServiceInterface _policyServiceInterface;
        public PolicyLayer(IPolicyServiceInterface policyServiceInterface)
        {
            _policyServiceInterface = policyServiceInterface;
        }

        public void DoSomethig()
        {
            _policyServiceInterface.DoSomething();
        }
    }

    public class Program
    {
        public static void Main(string[] agrs)
        {
           MachanismLayer machanismLayer=new MachanismLayer();
           PolicyLayer policyLayer = new PolicyLayer(machanismLayer);
           policyLayer.DoSomethig();
        }
    }
于 2011-06-02T13:51:25.777 に答える