Generics vs. Duplication

time to read 1 min | 103 words

imageI need to express the same logic over two different types. The code is literally the same in 90% of the cases, with minor modifications for each type. Seeking to avoid copy & paste programming, I decide to use some

public class BaseSpecificationController
<TSpecification, TSpecificationResult, TEntity> : BaseController where TSpecification : BaseSpecification<TEntity,TSpecificationResult> where TSpecificationResult : BaseSavedResult

The problem is that I got there, and it is really saving a lot of duplicated code. But still, I can't help but dislike such code, it seems like it is cheating.