0

What is the name for a class that does not have any side effects? Like a pure function, but a class.

In other words, what do you call a class where all methods are pure functions of the object's state and the method parameters, except that methods may have the side effect of updating the object's state (and therefore may not be idempotent)?

Is it a "pure class"?

Kerrick Staley
  • 1,583
  • 2
  • 20
  • 28
  • Is such a class allowed to mutate another class that it has an association with (but does not own)? – Chris Drew Oct 15 '18 at 18:30
  • 1
    "except that methods may have the side effect of updating the object's state"???? It's called a Class. It is not pure/functional at all. A functional class perhaps, eg. `java.lang.String`, returns new objects. – Sylwester Oct 15 '18 at 18:32
  • @ChrisDrew no, I don't think that's what I want. Methods' side effects should only be visible in their return values and the return values of other methods on the class. If you wanted to mutate another object in such a class, you would have to own the object, that object could not be borrowed anywhere else, and that object would also have to be "pure" (i.e. it can't print things to stdout). – Kerrick Staley Oct 15 '18 at 21:35

0 Answers0