nus-cs2103-AY2021S1 / forum

20 stars 2 forks source link

Ambiguity results from Omitting activation bar #491

Closed richardcom closed 3 years ago

richardcom commented 3 years ago

Hi!! In sequence diagram, it is mentioned that activation bars can be omitted if it results in no ambiguity. However, may I please clarify a little more on what are some of common conditions that might lead to ambiguity.

For example, in the following question, if the new Dog() is called by m instead, then under this situation, shall we consider that the simplified diagram is ambiguous. Since then we are unsure whether new Dog() is called by m.set(d) or is directly initiated in the m object instead(afterm.set(d) has already ended).

image

damithc commented 3 years ago

Can you provide the updated code that would make the diagram ambiguous?

richardcom commented 3 years ago

Hi Prof Damith, thank you for your reply. I was wondering for the code below, maybe the above sequence diagram might cause ambiguity between class 1 and class 2, since we are unsure whether new Dog() is called by m.set(d) or is directly initiated in the m object instead(afterm.set(d) has already ended).

Man m = new Man();
m.set();

// class 1
class Man {
    Dog d;
    void set() {
    }

    this.d = new Dog();
}

// class 2
class Man {
    Dog d;
    void set() {
        this.d = new Dog();
    }
}
damithc commented 3 years ago

🤔 class 1 code is not correct. this.d = new Dog(); is not inside a method.

richardcom commented 3 years ago

Oops, I am so sorry for this haha. Thank you Prof Damith @damithc ! I think maybe for most of the time omitting the activation bar will not cause much problem haha.