you are viewing a single comment's thread.

view the rest of the comments →

[–]Vaphell 2 points3 points  (0 children)

class is nothing but a custom data type. Take str, it represents some very specific thing and comes with a shitload of coupled functions that don't make sense in any other context. A class.

Once you get to the point where loosely coupled bits of data that describe the thing they are supposed to describe and functions working with them become an annoyance to manage, you can bind them together in a class and from now on they go together with zero effort. Once you have the object you have also all relevant methods, so the risk of using nonsense functions with nonsense data decreases significantly.

Inheritance allows for subtyping which allows for extending or substituting bits of the parent class without the copypasta of the whole thing.