7
This is the concept I’ve worked hard to understand, but I’ve never fully achieved.
I’ll take this excerpt from a Deitel book to illustrate:
It is a better software engineering define member functions outside the class definition. This practice ensures that programmers do not write a client code that depends on your class implementation. If they needed to do that, the client code probably 'would break' if the class implementation were changed.
I cannot understand how it would be possible for the client to write a code that depends on the class implementation, since the local variables of the method and the fields private
of the class are inaccessible in any way.
Could someone illustrate a practical example of code in which this could happen? An example library method exposed in which the user would use something specific to the implementation of this method in his code and then a possible change to that implementation by the creator of the library that would break client code. I need an example to understand. I’ve seen millions of conceptual explanations, but none made sense to me.
I find it even, in my layman’s view, more interesting to make implementations visible since the programmer may be curious to know how such a method works, just as one might wonder why when pressing a radio button, the station changes, for example.
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.
– Maniero