Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Refactoring Exercise: Refactoring intends to makes changes to the internal design of software without effecting any of the observable behavior of the system. You will

Refactoring Exercise:

Refactoring intends to makes changes to the internal design of software without effecting any of the observable behavior of the system. You will undertake a refactoring to make the software easier to understand and to modify, not to add new behavior as a result of the refactoring. The addition of new behavior, now possibly facilitated by the refactoring, can be done after you have verified that the refactored system behaving exactly like the original system. To accomplish this, you will need to follow a step-by-step process of small incremental changes that move you from the current design to the refactored design. Along the way, you will have parts of both old and new designs in place. At multiple points, you will want to run a full suite of tests to ensure that the system still behaves as it originally did.

For this exercise, list all of the steps that you would need to perform to complete a Replace Conditional with Polymorphism refactoring. Use following Refactoring Name: Replace Conditional with Polymorphism file for completing the exercise. Each step should be a small incremental change. The description of each step should be no more than a sentence or two. Indicate at what points you will do a system test to ensure that none of the behavior has changed. Make sure that after the last step the system will have evloved completely from the original design to the refactored design. There should be no vestiges of the original design left in the system that are not part of the refactored design.

You can assume that a test suite exists (It will right?) and simply add testing as a step in the sequence at all the points when you want to check that the steps just performed in the refactoring process maintained the integrity of the system behavior.

__________________________________

Replace Conditional with Polymorphism:

image text in transcribed

image text in transcribed

______________________________

Refactoring Name: Replace Conditional with Polymorphism:

In the list below specify the steps needed to perform the refactoring named above. Each step should be an incremental change to move the design from its current version toward the refactored design. There will need to be multiple steps performed to carry out the complete refactoring. At the end, there should be no remnants left from the original design that are not part of the new refactored design. Be sure that you include steps for testing. This will ensure that you have not progressed too far without checking that the system still exhibits the original behavior that was present before the refactoring began.

Refactoring Steps:

1...

You have a conditional that chooses different behavior depending on the type of an object. Move each leg of the conditional to an overriding method in a subclass. Make the original method abstract. double getSpeed() [ switch (type)5 case EUROPEAN: return getBaseSpeed(); return getBaseSpeed() - getLoadFactor)_numberOfCoconuts; return (isNailed)?0 getBaseSpeed(-voltage); case AFRICAN case NORWEGIAN BLUE: throw new RuntimeException ("Should be unreachable")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions