+ 10
what the goal of object oriented programming ?
I've been learning python using solo learn but I reached this part of oop (object oriented programming ) and I don't really understand how to use it in a program , can anyone help.
25 ответов
+ 8
Martin Taylor, as a Python fan, I want to publicly say:
Python's OOP is lacking.
In the beginning, I didn't understand that, but over time it sank in. 😂
In my own short words, an object is supposed to protect the data it contains, and define *from the inside* what can be done with that data, and what is forbidden, by providing methods.
If I can access anything from anywhere anyway, the object is effectively not protecting its data.
One question though:
You wrote, Python is not strongly typed. Is that correct?
Python is not statically typed, so you can basically pass everything as an argument, and the function has to sort out if that is even legit.
It's dynamically typed, so a variable name is not forever bound to one type of value, but it's just a 'sticker' that can be pasted onto everything.
Strongly typed, however, means, that one object can not be arbitrarily read as something completely different - which C for example allows.
At least that's how I've mostly seen it defined.
+ 5
I agree with Martin Taylor. While python can be used for OO programming, it does not offer the best experience.
In OOP, there should be a means to hide data from other classes. Python's does not have a `private` keyword and even if you prefix an attribute with two underscores it can still be called outside the class smh
Also, in other OO languages, you don't need to explicitly pass the instance when calling the instance method.
IMO Python does not deliver the best OOP developer experience
+ 5
So in situations (small code) where there is no need for robustness, Python looks short and easy.
But as soon as you want to make really sure, every method has to start with a bunch of tests, like:
If arg 1 is really an int and arg 2 is definitely a string and arg 3 is by no means blablabla...
+ 4
Bagon An important part of OOP is abstraction. A class should abstract away its implementation details(anything that is not significant to its use).
The reasons are thus:
1. Changing the implementation details will alter the behaviour of the class and may cause it to longer behave has a member of its type.
2. If the implementation details are made public. The developer can't know how far the client's have tampered with the objects and will be forced to release new versions with extreme caution because they will likely break things.
+ 4
It's better read some in the book and then learn