5

谁能指出下图的含义:

在此处输入图像描述

  1. PolicyLayer和PolicyServiceInterface是什么关系
  2. PolicyServiceInterface和MachanismLayer是什么关系。

C# 代码也将不胜感激!

请注意,UML 来自 Martin C. Robert,Martin Micah 2006 年的 C# 中的敏捷原则、模式和实践。

添加于 15 2011/6/2

执行以下具有相同含义的操作: 1) 一端为三角形的实线 2) 一端为三角形的虚线

2011/6/3 1日添加

有什么区别:1)一端带箭头的实线 2)一端带箭头的虚线

示例中的示例以及以下链接中的 PersistentObject 和 ThirdPartyPersistentSet:

UML 帮助 C# 设计原则

添加于 2011/6/3 第 2 次

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 使用 Policy 服务接口(可能它持有一个引用) 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 回答