Badda
Badda

Reputation: 1369

Is there any point in drawing an UML class diagram in functional programming?

I have been asked on a school project to show the UML diagrams I used - if I did - to realise the project. But the project I was working on was in C and has been functionally programmed. Thus I want to justify that using a class diagram when not using object oriented langage was pointless, but I am afraid that this is not true and haven't been able to confirm this hypothesis. It seems pointless to me but I'd like to know if it is the case, since may be thinking the code in a OOP way could help understanding how it works.

Is there any benefits regarding the way to think and build a functionnal program in using a class diagram ?

Upvotes: 6

Views: 2582

Answers (3)

Gangnus
Gangnus

Reputation: 24474

Of course, yes. The use of class diagram is not so extensive as in classical OOP, where very often having a class diagram means only automatic coding routine is left, but still it is very useful for:

  1. Planning of data structures (We still should understand data and their interconnections)
  2. Creating the hierarchy of methods. (Grouping of methods up to their data and tasks)
  3. Tying together methods and some special data. (What method works with what classes of data)
  4. If the language supports OOP, you can use a class diagram translating it into code.

And even if you haven't any OOP features supported, you can always profit from at least the first point.

Really, the only possible use of the class diagram, that is forbidden by functional programming, is creation of methods with side effects on instances. And that is not much connected to the class diagrams. On the contrary, class diagrams are not mentioned for modelling of that. Rather the Composite Structure Diagrams are.

Upvotes: 5

qwerty_so
qwerty_so

Reputation: 36313

If you are going to document FP with OO you will deviate your FP to OO. That might not be the worst, but definitely class diagrams in FP are pointless.

However, UML has more to offer than class diagrams. You will definitely benefit from state diagrams. Eventually from timing diagrams. And in a limited sense from sequence diagrams. The latter would only make sense if you can show "information tokens" equivalent to messages used in SDs.

Finally a higher level picture could be sketched using activity diagrams.

Upvotes: 2

Appyx
Appyx

Reputation: 1185

There is a point in creating a diagram.

Think of a struct as a class.

A struct maybe contains other structs.

So you have a relation from one type to another. With UML you can model the relationships of your structs and this is really helpful in larger projects.

If you dedicate a file.c to a struct you could think of a real class, if every function of the file.c takes an instance of the struct as parameter.

Upvotes: 3

Related Questions