1

I am playing with sequence diagram. And main question is how to draw properly on sequence diagram interaction with variable. How to draw

1) When MakePayment aggregates person

insurance.MakePayment(person.FirstName, person.SecondName, 20);

2) Variable assignment

internalVariable = SecondName;

I am not sure that I draw right sequence.

enter image description here

namespace Example
{
    public class Person
    {
        public string FirstName { get; set; }

        public string SecondName { get; set; }

        public string Salary { get; set; }
    }

    public class Insurance
    {
        private readonly Bank bank;

        public Insurance()
        {
            bank = new Bank();
        }

        public bool MakePayment(string FirstName, string SecondName, int value)
        {
            if (bank.GetBalance(FirstName, SecondName) > value)
            {

            }
            return true;
        }
    }

    public class Bank
    {
        private string SomeVariable { get; set; }

        private string internalVariable;

        public Bank()
        {

        }

        public decimal GetBalance(string FirstName, string SecondName)
        {
            SomeVariable = FirstName;
            internalVariable = SecondName;
            return 320;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Person person = new Person();
            person.FirstName = "FirstName";
            person.SecondName = "SecondName";
            Insurance insurance = new Insurance();
            insurance.MakePayment(person.FirstName, person.SecondName, 20);
            PrintResult(person.FirstName);
        }

        public static void PrintResult(string firstName)
        {
            Console.WriteLine(firstName);
        }
    }
}
1
  • Note on terminology. What you call "internal variable" is usually called "member variable" or "fields". All member variables combined are referred to as "state" [of an object], even when we aren't discussing a state machine. Mar 30, 2019 at 23:50

1 Answer 1

2

I think you're putting to much information in your diagram. You can of course, but this kind of diagrams are usually used to show, as simply as possible, the interactions between actors in a use case.

In this case, the actors would be:

  1. The User clicking on the Make payment button.
  2. The Insured person receiving the money from the insurer.
  3. The Insurer.
  4. The Bank.

The messages exchanged would be:

  1. User to Insurer: Make Payment (Parameter=Insured)
  2. Insurer to bank: Get Balance (Parameter=Account)
  3. Bank to Insurer: Done (Parameter=Balance)
  4. Insurer to bank: Transfer Money (Parameters=Amount, Insurer Account, Insured Account)
  5. Bank to Insurer: Done (Parameter=Transaction code)
  6. Insurer to User: Done (Parameter=Transaction code)

You could also show on the same diagram the interaction resulting for insufficient funds, or create a new use case for this.

Object creation should not be shown, unless it is crucial (if you want to show how an object factory create an object, for example).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.