Code duplication on different contexts is considered as duplication

java
duplications
sonarqube

(Jakub Pawliński) #1
  • 6.7.2 (build 37468)
  • Duplicated Lines on New Code (%)

Example code:

    public class User
    {
        public string Firstname;
        public string Surname;

        public string getFullname()
        {
           return computeFullName;
        }
    
        private string computeFullName()
        {
            return $"{Firstname} {Surname}";
        }
    }
    
    public class Car
    {
        public string Make { get; set; }
        public string Model { get; set; }

        public string getFullname()
        {
            return computeFullName;
        }
    
        private string computeFullName()
        {
            return $"{Make}/{Model}";
        }
    }

public string getFullname() is consiereded as duplicate, while making those two totally not related classes using common base class would be a mistake