
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A practice quiz on design refactoring, focusing on techniques such as renaming methods, encapsulating fields, replacing iteration with recursion, and extracting classes. It covers principles like cohesion, coupling, and the open-closed principle. Students will learn how to make code more readable, maintainable, and efficient.
Typology: Quizzes
1 / 1
This page cannot be seen from the preview
Don't miss anything!

1) b When a method name does not reveal its purpose, change the name of the method. Use the refactoring “ Rename Method” to change empty to isEmpty (unless empty does really empty the container). BTW: The C++ STL has many collection classes (stack, queue, list) where empty does not mean empty, it returns true if the stack isEmpty. Also, pop can modify and return as long as it is documented. You could argue that pop should only modify, and some people do. 2) b Whenever there is a public field, make it private and provide accessors. This prevents other object from modifying a field, which would be the worst form of coupling. Use the "Encapsulate Field" refactoring (Eclipse has this refactoring) 3) a The while loop is difficult to read, trace, and understand. And it is longer. The recursive solution can be easier to understand. Use the refactoring Replace iteration with Recursion to make more readable code. BTW: Worried about all of those method calls at runtime? A compiler can make the code to the left run as fast as the code to the right. And you should wait until you profile the code to see if this is a bottleneck 4) b When you have a complicated conditional (if-then-else) statement, use the refactoring " Decompose Conditional". Extract methods from the Boolean condition 4B) Yes Apply " Rename Method" and have the method return the logical negation, then apply **"Reverse Conditional"