Home > Software engineering >  Strategy Sequence Diagram
Strategy Sequence Diagram

Time:01-25

I am trying to create a sequence diagram and I am not sure I am doing it correct, because inside Sort function in Sorter Class has for example the strategy DownComparer that will be called more than one time. Does the Arrows from ShouldSwap and the return bool value from SortStrategy->Sorter should look like I did or it should look like something else?

enter image description here

public class Sorter
{
    public IComparer m_Comparer { get; set; }

    public Sorter(IComparer i_Comparer)
    {
        m_Comparer = i_Comparer;
    }

    public void Sort(ref ListBox i_ListBox)
    {
        for (int i = 0; i < i_ListBox.Items.Count - 1; i  )
        {
            for (int j = i   1; j < i_ListBox.Items.Count; j  )
            {
                if (m_Comparer.ShouldSwap(i_ListBox.Items[i] as Group, i_ListBox.Items[j] as Group))
                {
                    doSwap(i_ListBox.Items, i, j);
                }
            }
        }
    }

    private void doSwap(ListBox.ObjectCollection i_Items, int i_Index1, int i_Index2)
    {
        object temp = i_Items[i_Index1];
        i_Items[i_Index1] = i_Items[i_Index2];
        i_Items[i_Index2] = temp;
    }
}

CodePudding user response:

I'm assuming the idea here is to repeat the ShouldSwap until it returns false (or true depending how you wrote it). If yes, then you should show a loop using Combined Fragment.

I don't have a UML drawing tool at hand at the moment, but you can read about this particular Combined Fragment type (loop) for example on uml-diagrams.org page. In general I recommend it for study as it contains description of most if not all elements existing in UML, following specification and sometimes referring also other sources.

  •  Tags:  
  • Related