xeraphim
xeraphim

Reputation: 4645

Correct UML diagram for dependency injection

I have following classes:

public interface IRule { void Execute(int i); }
public interface IRule1 : IRule { }
public interface IRule2 : IRule { }
public interface IRuleExecutor { void Execute(int i) }

public class Rule1 : IRule1 { public void Execute(int i) { } }
public class Rule2 : IRule2 { public void Execute(int i) { } }

public class RuleExecutor : IRuleExecutor
{
    private ICollection<IRule> allRules;

    public RuleExecutor(ICollection<IRule> rules)
    {
        this.allRules = rules;
    }

    public void Execute(int i) { }
}

What is the correct way to display these classes (especially the relationship between RuleExecutor and the rules) in a UML class diagram?

Thanks in Advance

Upvotes: 0

Views: 3316

Answers (1)

www.admiraalit.nl
www.admiraalit.nl

Reputation: 6089

There are several options, but this is how I would model it:

UML diagram

I haven't explicitly modeled ICollection. It is implicitly represented by the multiplicity "*" on the side of IRule. A rule can be associated with multiple RuleExecutors, so I have put an asterisk on the side of RuleExecutor as well. The association is directed from RuleExecutor to IRule, because RuleExecutor has a reference to IRule, but not vice versa.

Upvotes: 4

Related Questions