Dec-28-2018, 08:00 PM
There are no cases where classes are required.
Python is a great example, being written in C, which itself doesn't support classes. It then follows, that anything in python is also possible in C, and that anything you could accomplish with a class, you could also accomplish without one.
So no, there are no cases where a class is essential over a function.
That said, they were created for a reason, and that reason is state management. If you have state you're keeping track of, classes help encapsulate that state, as well as grouping related functions together to strongly indicate to other readers that the functions are, in fact, related to one another.
Python is a great example, being written in C, which itself doesn't support classes. It then follows, that anything in python is also possible in C, and that anything you could accomplish with a class, you could also accomplish without one.
So no, there are no cases where a class is essential over a function.
That said, they were created for a reason, and that reason is state management. If you have state you're keeping track of, classes help encapsulate that state, as well as grouping related functions together to strongly indicate to other readers that the functions are, in fact, related to one another.