my question is about how to work with inheritance in a functional way in F #. To describe this a bit, I will give a simple example. Suppose we want to model a world made up of different kinds of animals. Each animal species has some attributes with other species (e.g. name, size, etc.). In addition, each species may have others that are not shared by others (for example, the number of children is related to dogs and cats, but not for spiders, for example). In addition, there may be methods or functions associated with each animal species that may or may not be the same for the two animal species, that is, there is a default implementation that may be excessive for a particular species. Each animal species may have a method (s) that is defined only for that kind.
Now, in the OOP world, this is likely to lead to an abstract class having common attributes and abstract methods, followed by classes obtained for each animal species. I am not sure how to functionally define a domain model in F #. Here: What to use, an abstract class or interface in F #? states that "the idiomatic code of F # uses different extensibility points than C # (for example, using a function / interface as an argument), so you really don't need abstract classes."
If this is the way that should be adopted, is it possible to provide some basic example of this?
As for my further reflection on this, I believe that attributes should be encapsulated in some kind of structure. Then most of the idiomatic structure in this regard in F # is a notation. Does this mean that there should be a parent record, which should be included in other records corresponding to specific "children", i.e. Compositions instead of inheritance. This, however, seems to me a workaround that is neither idiomatic nor particularly elegant.
I think the preferred way to model inheritance in F # is through discriminatory unions. However, this does not solve the problem of common attributes and methods.
Models similar to those mentioned above are quite common, in my opinion, since they are implicitly included in most enterprise applications. So, is there any suggestion on how this can be handled in a functional way (for example, the method suggested by the link above or any other suggestion)? Or will we say that this is not a domain that can be easily modeled using a functional approach?
Thanks.