UML help C# Design Principles

霸气de小男生 提交于 2019-12-04 08:11:34
SwDevMan81

1) What is the relationship between PolicyLayer and PolicyServiceInterface

The -----> is Association ("knows a")


(source: sedris.org)

C# code:

public interface PolicyServiceInterface { }

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

2) What is the relationship between PolicyServiceInterface and MachanismLayer.

The - - -|> is Realization ("implements")

C# Code:

public interface PolicyServiceInterface { }

public class MachanismLayer : PolicyServiceInterface 

3) Do the following have the same meaning: 1) A solid line with a triangle at one end 2) A dashed line with a triangle at one end?

No they have different meanings:

The -----|> is Generalization ("inherits")

C# Code:

public class PolicyServiceInterface { } // could also be abstract

public class MachanismLayer : PolicyServiceInterface 

What is the difference between: 1) A solid line with an arrow at one end 2) A dashed line with an arrow at one end

The - - -> is Dependency ("uses a") There are various forms of dependency including local variables, parameter values, static function calls or return values.

C# Code:

// 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();
   } 
}

See my answer here for Composition and Aggregation.

PolicyLayer uses Policy service interface(probabily it holds a reference) MachanismLayer implements 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();
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!