Javaв„ў EE 5 Tutorial, The (3rd Edition)

In the middle of that discussion, Chet s wife Sue showed up and we had dinner; then they went home. I m on my own again now. Keep an eye out for the mistakes that I d have avoided if I d had him to pair with.

Lesson  

You may be tempted to design something better to take care of all these special cases. Frankly, a while back in our programming experience, so would we. But we ve learned something powerful and interesting about simple code: if we simply find and remove duplication in obvious ways, we usually wind up with code that s much cleaner and clearer. sb Removing duplication is your friend. So let s just do that and see what happens.

First let s scan for duplications:

In the end, it s all a matter of taste what you go after. You ll likely wind up with much the same code in every case, and you ll wind up with much better code for sure.

Категории