axylotl
axylotl

Reputation: 35

Modeling a VUE app with UML Class and Sequence Diagram

I am trying to model a part of my VUE app with UML. I used a class diagram to show the structure and a sequence diagram to show one specific behavior.

There are some things I am not sure about:

Here, the draft of the UML class-diagram sketching the VUE app:

enter image description here

And the sequence diagram:

enter image description here

And here the description of what this app does:

You can find the implemented part of the application here.

Upvotes: 3

Views: 4302

Answers (1)

Christophe
Christophe

Reputation: 73500

The key question here is not whether UML is suitable for the job or not, but what do you want to show in your diagrams:

In this other question I have developed what relevant diagrams could be used for in a JS context with Electron. I think it may answer your question about which diagrams to use.

You have opted for a class diagram. It explains well the the internal structure based on classes and their relationships:

  • A Vue component can be represented by a class:

    Components are reusable Vue instances with a name (source: Vue guide)

  • props may be shown it as an UML property:

    Props are custom attributes you can register on a component. When a value is passed to a prop attribute, it becomes a property on that component instance. (source: Vue guide)

    UML classes are usually represented with a box with 2 separators. The first part is the class name, the second part is for the properties and a third part are for operations. Since props can be accessed from other components, it seems better to give them a public accessibility in the class diagram (+ instead of -)

  • Computed properties could be shown as derived properties, i.e. with its name preceded by /:

(...) its value or values may be computed from other information. Actions involving a derived Property behave the same as for a nonderived Property. Derived Properties are often specified to be read-only (i.e., clients may not directly change values). But where a derived Property is changeable, an implementation is expected to make appropriate changes to the model in order for all the constraints to be met, in particular the derivation constraint for the derived Property. (source: UML specifications)

  • Your “methods” are operations in UML,.

  • I’m not a Vue expert, but I understand that “watchers” seem to be some special kind of methods.

More generally, I'd suggest to use a custom UML profile for Vue. It may define stereotypes for each of these kind of elements (e.g. «Vue component», «props», «computed») that would precede the name of the element or be above it. This could convey a more precise semantic, especially if there could be ambiguities (e.g. methods vs watchers).

Your narrative explains the interaction between components. This is best documented with a sequence diagram. Lifelines would be instances of components or props instances of a component, and messages exchanged between lifelines would correspond to Vue methods, and other means to exchange information.

Upvotes: 4

Related Questions