+ 2
What is the full purpose of Classes?
I was thinking about functions, variables and code organization, but then I remembered about classes. I know how they're used, but I don't know how they fully work.
1 ответ
+ 4
the full purpose of classes is to provide to encapsulate data, mark data and the methods that operate on that data as related and to provide a way to efficiently map the mental model of the world we have to code(most people think about objects for example "the car is driving").classes also help to model A contains B relationships.
when talking about inheritance we also see that classes allow us to model A is a B relationships. for example A human is an animal
and downcasting models this B is an A. so this animal in a human
if you want to see the whole power of classes you should learn about design patterns(of course design patterns are not really about object oriented programming, but they show its power very nicely). but don‘t use the sololearn course it‘s not that good
some keywords to get you started are singleton, abstract factory, factory method, model view controler,object pools, Builder, Adapter