blackhorse wrote:Well, that is just my experience, if I read functions codes, I would have to kind take more time to see how these functions work, they work on what values, what functions return these values, how these functions interact with other codes. And each developer may have his own way to write functions.
That is true, but the methods of a class are functions, and these same ideas of the pre-conditions and post-conditions of functions apply to methods.
blackhorse wrote:But if in class, values are in class variables. set functions to set the values, get functions to get the values, etc. that is oop 101. Most people will do the same way. When you read class code, you know what you expect for.
A class that consists (almost) entirely of getter and setter functions might not be very well designed, since it might not be providing the correct abstractions for what the class is supposed to model.
blackhorse wrote:In simple words, I think even no inheritance, if the code is write in class rather than just function, in most cases, it is cleaner and simpler. You may not call it 100% OOP, but still a good programming practice.
Ah, but doesn't that complicate the answering of your original question? 😃 If it is not 100% OOP, what percentage of OOP is it? :p
Now, let me present another scenario: you define a class and release it as part of a library. Some time later, some users of your library request that you extend the class' functionality by providing some convenience functions. These convenience functions can be implemented entirely using the public interface of your class, with negligible impact on performance. Would you make them methods or free functions, or would you use inheritance?
Chances are, I would choose the make them free functions. The reason is that if you make them members, then you decrease the encapsulation of the class, in the sense that a change to the implementation of the class requires you to check more functions to see what impact that change might have. If they are free functions instead, then as long as the methods that they rely upon do not change in functionality, they too will not change in functionality. The use of inheritance is feasible, but you may need to implement extra code, e.g., to forward constructor invocations.
The point is that the use of free functions here increase, not decrease, encapsulation, and encapsulation is one of the things people consider when they talk about OOP. In other words, a naive "compare how much code is in free functions versus how much code is in classes" is not a good gauge of the extent that OOP is used.