How to represent “event” in a UML Class Diagram?

匆匆过客 提交于 2019-12-05 18:16:35

问题


This is my code snippet

public class Notation : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    private Notes _note;
}

How to write public event PropertyChangedEventHandler PropertyChanged; in UML Class diagram properly?

First, I think it's :

+PropertyChanged: PropertyChangedEventHandler

But then, I realized that it doesn't represent the event part of the code.

Any idea? Thanks


回答1:


Here comes the UML stereotype in the game. Just stereotype this property:

Note that _note is a plain privat property.




回答2:


You can define receptions in class definition. Reception is type of behavioral feature. If you define it, instance of class can accept signal events from environment. Other way to define events in UML is using behavioral diagrams. Activity diagram has event element to accept events of specific types during execution. State Machine diagram has transitions with trigger definition, which represents event acceptance as well. Interaction diagram represents events as receiving or sending messages. Behavior definitions (represented by behavioral diagrams) can be assigned to class definition as classifier behavior or owned behaviors. Owned behavior definition defines ability of owning class to react on event occurrences.

Your example just defines attribute of class, but not ability to accept event by class instance.



来源:https://stackoverflow.com/questions/24681328/how-to-represent-event-in-a-uml-class-diagram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!