Loose coupling

Whenever possible, reduce coupling or dependence in your program. The following is a famous quote on this subject:

All problems in computer science can be solved by another level of indirection.
                                                                                                      – David Wheeler

Let's suppose that your program has a play button. An immediate impulse may be to link it to the play method of your program. However, you can further break it up into two methods. You could probably link the play button to a method named on_play_button_clicked, which in turn calls the actual play method. The advantage of this is that you may want to handle additional things when the play button is clicked, such as displaying the current track information somewhere in your program.

Thus, you can now use the on_play_button_clicked method to decouple the click event from the actual play method and then handle calls to multiple methods. 

However, you must resist the temptation of adding too many levels of indirection, as your program may quickly start getting messy and it may get out of control.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.79.147