Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UML help C# Design Principles

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

like image 386
Pingpong Avatar asked Jun 02 '11 13:06

Pingpong


2 Answers

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.

like image 148
SwDevMan81 Avatar answered Sep 20 '22 20:09

SwDevMan81


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();
        }
    }
like image 30
Massimiliano Peluso Avatar answered Sep 24 '22 20:09

Massimiliano Peluso