Search code examples
functional-programmingumlclass-diagram

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 ?


Solution

  • 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.