When to use case class or regular class

If you are going to write purely functional code with immutable objects, you should better try avoid using regular classes.
The main idea of the functional paradigm is the separation of data structures and operations on them.
Case Classes are a representation of a data structure with the necessary methods. Functions on the data should be described in different software entities (e.g., traits, objects).

Regular classes, on the contrary, link data and operations to provide the mutability. This approach is closer to the object-oriented paradigm.


As a result, do not use Case Classes if:

  1. Your class carries mutable state.
  2. Your class includes some logic.
  3. Your class is not a data representation and you do not require structural equality.

However, in these cases, you should really think about the style of your code because it probably is not functional enough.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)