Skip to content

"Consolidate Duplicate Conditional Fragments" solution does not address the problem fully #112

Open
@grimsa

Description

@grimsa

See this problem: https://refactoring.guru/consolidate-duplicate-conditional-fragments

The problematic code is:

if (isSpecialDeal()) {
  total = price * 0.95;
  send();
}
else {
  total = price * 0.98;
  send();
}

The proposed solution is:

if (isSpecialDeal()) {
  total = price * 0.95;
}
else {
  total = price * 0.98;
}
send();

yet it still duplicates the logic of calculating the total.

A better solution would be something like this:

total = price * (isSpecialDeal() ? 0.95 : 0.98);
send();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions