UML help C# Design Principles
Asked Answered
D

2

5

Could anyone please point out the meaning of the graph below:

enter image description here

  1. What is the relationship between PolicyLayer and PolicyServiceInterface
  2. What is the relationship between PolicyServiceInterface and MachanismLayer.

C# code would be also appreciated!

Please note that the UML is from Agile Principles, Patterns, and Practices in C# By Martin C. Robert, Martin Micah 2006.

Added on 15 2011/6/2

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

Added on 2011/6/3 1st

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

Example in thie sample and PersistentObject and ThirdPartyPersistentSet in the link below:

UML help C# Design Principles

Added on 2011/6/3 2nd

Can the relationship between PolicyLayer and PolicyServiceInterface as below:

public class PolicyLayer

{
    private PolicyServiceInterface policyServiceInterface = new PolicyServiceInterfaceImplementation();
}

class PolicyServiceInterfaceImplementation:PolicyServiceInterface {}

Regarding

Dewy answered 2/6, 2011 at 13:46 Comment(1)
Related: #6208808Graze
G
7

1) What is the relationship between PolicyLayer and PolicyServiceInterface

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

Association
(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")

Realization

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")

Generalization

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.

Dependency

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.

Graze answered 2/6, 2011 at 13:55 Comment(5)
@Graze thank you for your advice. 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 endDewy
@SwDevMan81, Thank you for your advice. I noticed that the C# for realization is different from what I thought. 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 In C#, there is a difference in the way that a method parameter is or is not used. In C#, there is a difference in the way that a method parameter is used.Dewy
@Dewy - I've updated my answer to address your latest questionGraze
@Graze Thank you for your advice again. Please review my update on 2011/6/3 1st and 2nd.Dewy
@Dewy - I already address 1st, and for 2nd, no, that is composition (The diamond symbol)Graze
E
2

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();
        }
    }
Erde answered 2/6, 2011 at 13:51 Comment(6)
@Massimiliano Peluso, thanks for your advice! Why do both A solid line and a dashed line with a triangle at one end has the same meaning?Dewy
the difference is between a normal arrow and the one with the triangle at the end. the first one mean it uses the second of it type of: agilemodeling.com/artifacts/classDiagram.htmErde
Sorry, I might not make my self clear. I meant the difference between 1)a solid line with a triangle at the end. 2) a dashed line with the same triangle at the end.Dewy
In the class diagram you should only use solid line: the dashed doens't mean anything in this diagram. In the Sequence Diagram the dashed line is used to show an Async message and the solid line for a Sync one but again in this case all the line should be solidErde
@Massimiliano Peluso thank you for your advice. But i think it does have difference. solid line with triangle: implement in c#, whereas, dashed line with triangle: inherit.Dewy
UML notation is not related to any language. Dashed line is not documented for class diagramErde

© 2022 - 2024 — McMap. All rights reserved.