The Java Course provides a general introduction to programming in Java. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details. 
Home Create Your Own Objects Generalization  
Search the VIAS Library  Index  
Generalization
In some ways converting from base 60 to base 10 and back is harder than just dealing with times. Base conversion is more abstract; our intuition for dealing with times is better. But if we have the insight to treat times as base 60 numbers, and make the investment of writing the conversion methods (convertToSeconds and the third constructor), we get a program that is shorter, easier to read and debug, and more reliable. It is also easier to add more features later. For example, imagine subtracting two Times to find the duration between them. The naive approach would be to implement subtraction complete with "borrowing." Using the conversion methods would be much easier. Ironically, sometimes making a problem harder (more general) makes is easier (fewer special cases, fewer opportunities for error).


Home Create Your Own Objects Generalization 