I'm taking a course on design patterns in software engineering and here I'm trying to understand the good and the bad way of design relating to coupling and cohesion.I could not understand the concept described in the following image. The example of code shown in the image is ambiguous to me, so I can't quite clearly get what exactly Ask, don't tell! approach mean. Could you please explain?
Explanation needed, for Ask, don't tell approach?
design patterns;object oriented design;design
The first example tells the object in question, I need these accessors and this data from those accessors. That may be fine and good but it requires that you know how the object accesses those things.The second example asks the object Can you do this thing?, and then the object either returns that operation or fails. There is no requirement of internal knowledge of the object, thus facilitating the idea of loose coupling since I can then freely change the underlying object's interal functionality so long as the accessor interface, the tum.addStudentToLecture(...), remains the same.