Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Feature envy is one of the bad smells in Martin Fowlers?s codesmells. Feature envy describes a situation in which one object getsat the fields of

Feature envy is one of the bad smells in Martin Fowlers?s codesmells. Feature envy describes a situation in which one object getsat the fields of another object to perform some sort of computationor make a decision, rather than asking the object to do thecomputation itself. Inthe Customer class below, themethod getMobilePhoneNumber()provides a NorthAmerican-formattedmobile Phone number.

Note: Suppose the customer class is createdseparately.

Note: Suppose the customer class is createdseparately.

image

Rewritethe Phone and Customer classto remove the ?feature envy? bad smell improving thecode. [12-Marks]

public class Phone { private final String unformatted Number; public Phone (String unformattedNumber) { this.unformattedNumber=un formattedNumber; } } public String getAreaCode() { return unformatted } public String getPrefix() { return } Number.substring(0,3); public String getNumber() { } public class Customer{ unformattedNumber.substring(3,6); return unformatted Number.substring(6, 10); } private Phone mobilePhone; public String getMobile PhoneNumber() { return "(" + } mobile Phone.getAreaCode() + ") + mobilePhone.getPrefix() + "_" + mobile Phone.getNumber();

Step by Step Solution

3.51 Rating (154 Votes )

There are 3 Steps involved in it

Step: 1

To remove the feature envy code smell in the given Phone and Customer classes we can refactor the co... 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

Recommended Textbook for

Accounting Information Systems

Authors: George H. Bodnar, William S. Hopwood

11th Edition

0132871939, 978-0132871938

More Books

Students also viewed these Programming questions