Suppose that I have two services Person Service and Company Service and I want to maintain links between them for example a Person is linked to Company because he works there or he owns the company etc. So I will go ahead and create a database table like
PersonId, CompanyId, RelationType
Now the business logic can be written in either of the services that client will call to link them. But what if I have requirement to link multiple person to a single company and multiple companies to a single person. I need to have two methods, one that takes single PersonId and list of CompanyIds and one that takes single CompanyId and multiple PersonIds. So I have written two different methods in each service. Following method is in Person Service
void LinkPersonToCompanies(long personId, IEnumerable<long> companyIds, RelationType type)
and below method is in Company Service
void LinkCompanyToPersons(long companyId, IEnumerable<long> personIds, RelationType type)
I know that these are two different methods but they are doing the same task i.e. their logic repeats itself. It can become tough to maintain because a single change in linking mechanism should now be made to both methods. Is it against DRY principle? What should be the right design to efficiently solve this problem?