I have the following interface:
public interface ISearchProperties {
string CurrentUserLocation { get; set; }
string SearchUsername { get; set; }
}
With the following implementations:
public class BroadcastPreviewDto : ISearchProperties {
// other properties
}
public class ProfileSearchDto : ISearchProperties {
// other properties
}
I have the following functions:
public void PrepSearchProperties(ProfileSearchDto query) {
// do a bunch of stuff to query properties here (only on ISearchProperties properties)
}
public void PrepSearchProperties(BroadCastPreviewDto query) {
// do a bunch of same stuff to query properties here (only on ISearchProperties properties)
}
The problem is that this isn't very DRY - the function bodies are exactly the same thing. I tried doing this:
public void PrepSearchProperties(ISearchProperties query) {
// do a bunch of stuff to query properties here
}
But this doesn't quite work unless I declare the original query
as ISearchProperties
, which strips the implementing class properties.
What pattern can I follow to DRY my code up?