Functional Classes

This post was originally published on this site

Clean Coder

I recently tweeted the following:

Should you subdivide a functional program into classes the way you would an object oriented program?

Yes. You should. Because the rules don’t change just because you’ve chosen to use immutable data structures.

— Uncle Bob Martin (@unclebobmartin) January 17, 2023

This led to a bevy of interesting responses about the difference between classes and modules. In answer to those responses I tweeted this:

A class is a group of cohesive and narrowly defined functions that operate on an encapsulated data structure. The functions may, or may not, be polymorphically deployed.

— Uncle Bob Martin (@unclebobmartin) January 17, 2023

Of course that only led to an increased number of interesting responses. And so I thought that it might be wise to blog about my reasoning rather than to continue trying to cram that reasoning into tweets.

If you are in doubt about what FP is, and about what

To read the full article click on the 'post' link at the top.