Refactoring Code

When your unit tests all pass, it is time to reorganize code. For example, if you take a look at the Rectangle class, you notice that the Generate from Usage Feature generated objects of type Integer, and this is also the reason why the CalculatePerimeter method has been forced to return Integer. Although correct, the most appropriate type for math calculations is Double. Moreover, you might want to consider writing a more readable code in the method body. After these considerations, the Rectangle class could be reorganized as follows:

image

In this way you have working code that uses more appropriate types and that is more readable.

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

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