Skip to main content
changed IDnsUserBlacklistService to IUserBlacklistService, that was a mistake as I refer above to IUserBlacklistService
Source Link
public class DnsUserBlacklistService: IDnsUserBlacklistServiceIUserBlacklistService
{
    private readonly IDnsService _dnsService;
    private readonly String _domain;

    public DnsUserBlacklistService(IDnsService dnservice, String domain)
    {
        _dnsService = dnsService;
        _domain = domain;
    }

    public Boolean IsUserBlacklisted(IsUserBlacklistedRequest request)
    {
        var subDomainToQuery = GetSubDomainToQuery(request);
        var fullDomainToQuery = String.Format("{0}.{1}", subDomainToQuery, _domain);

        var dnsRecords = _dnsService.GetRecords(fullDomainToQuery);
        if (dnsRecords != null && dnsRecords.Any())
        {
            // Match between records and user information
            // Note: I know I shouldn't write pseudo-code, but this part
            // is really unrelevant to the question
        }

        // If no DNS records, assume the user is not blacklisted
        return false;
    }

    private String GetSubDomainToQuery(IsUserBlacklistedRequest request)
    {
        return String.Concat(
            request.FirstName,
            request.LastName,
            request.BirthDate.ToString("yyyyMMdd")
        );
    }
}
public class DnsUserBlacklistService: IDnsUserBlacklistService
{
    private readonly IDnsService _dnsService;
    private readonly String _domain;

    public DnsUserBlacklistService(IDnsService dnservice, String domain)
    {
        _dnsService = dnsService;
        _domain = domain;
    }

    public Boolean IsUserBlacklisted(IsUserBlacklistedRequest request)
    {
        var subDomainToQuery = GetSubDomainToQuery(request);
        var fullDomainToQuery = String.Format("{0}.{1}", subDomainToQuery, _domain);

        var dnsRecords = _dnsService.GetRecords(fullDomainToQuery);
        if (dnsRecords != null && dnsRecords.Any())
        {
            // Match between records and user information
            // Note: I know I shouldn't write pseudo-code, but this part
            // is really unrelevant to the question
        }

        // If no DNS records, assume the user is not blacklisted
        return false;
    }

    private String GetSubDomainToQuery(IsUserBlacklistedRequest request)
    {
        return String.Concat(
            request.FirstName,
            request.LastName,
            request.BirthDate.ToString("yyyyMMdd")
        );
    }
}
public class DnsUserBlacklistService: IUserBlacklistService
{
    private readonly IDnsService _dnsService;
    private readonly String _domain;

    public DnsUserBlacklistService(IDnsService dnservice, String domain)
    {
        _dnsService = dnsService;
        _domain = domain;
    }

    public Boolean IsUserBlacklisted(IsUserBlacklistedRequest request)
    {
        var subDomainToQuery = GetSubDomainToQuery(request);
        var fullDomainToQuery = String.Format("{0}.{1}", subDomainToQuery, _domain);

        var dnsRecords = _dnsService.GetRecords(fullDomainToQuery);
        if (dnsRecords != null && dnsRecords.Any())
        {
            // Match between records and user information
            // Note: I know I shouldn't write pseudo-code, but this part
            // is really unrelevant to the question
        }

        // If no DNS records, assume the user is not blacklisted
        return false;
    }

    private String GetSubDomainToQuery(IsUserBlacklistedRequest request)
    {
        return String.Concat(
            request.FirstName,
            request.LastName,
            request.BirthDate.ToString("yyyyMMdd")
        );
    }
}
Post Reopened by syb0rg, RubberDuck, rolfl
deleted 235 characters in body; edited tags
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Note: This post has been copied from this StackOverflow topic Edit: Made the code more real so the question can be replied to. Sorry, everyone.

I've been trying for a while to write clean and testable code, with the help of DI and abstractions.
I found myself guilty of service-itis, creating 3 or 4 interfaces for something that clearly doesn't need it. So I decided to relax, and only abstract what really needs it.

In the end, my question is: am I going too far with abstractions?
Maybe some thoughts on this particular example could help me decide in the future where to stop.

I hope I was clear, thanks for reading if you made it to the end ;-)

Note: This post has been copied from this StackOverflow topic Edit: Made the code more real so the question can be replied to. Sorry, everyone.

I've been trying for a while to write clean and testable code, with the help of DI and abstractions.
I found myself guilty of service-itis, creating 3 or 4 interfaces for something that clearly doesn't need it. So I decided to relax, and only abstract what really needs it.

In the end, my question is: am I going too far with abstractions?
Maybe some thoughts on this particular example could help me decide in the future where to stop.

I hope I was clear, thanks for reading if you made it to the end ;-)

I've been trying for a while to write clean and testable code, with the help of DI and abstractions.
I found myself guilty of service-itis, creating 3 or 4 interfaces for something that clearly doesn't need it. So I decided to relax, and only abstract what really needs it.

In the end, my question is: am I going too far with abstractions?
Maybe some thoughts on this particular example could help me decide in the future where to stop.

added 1826 characters in body
Source Link

Note: This post has been copied from this StackOverflow topic Edit: Made the code more real so the question can be replied to. Sorry, everyone.

public interface IUserBlacklistService
{
    Boolean IsUserBlacklisted(IsUserBlacklistedRequest request);
}

public class IsUserBlacklistedRequest
{
    //public PropertiesString representingFirstName
 necessary data to determine{
 if the      get;
    // user is blacklisted set;
    }

    public String LastName
    {
        get;
        set;
    }

    public DateTime BirthDate
    {
        get;
        set;
    }

    public String BirthCity
    {
        get;
        set;
    }

    public String BirthCountry
    {
        get;
        set;
    } 

    public String BirthDepartment
    {
        get;
        set;
    }
}
public interface IDnsService
{
    IEnumerable<DnsRecord>IEnumerable<String> GetRecords(String queriedDomain);
}

So the class DnsUserBlacklistService would look like this:

public class DnsUserBlacklistService: IDnsUserBlacklistService
{
    private readonly IDnsService _dnsService;
    private readonly String _domain;

    public DnsUserBlacklistService(IDnsService dnservice, String domain)
    {
        _dnsService = dnsService;
        _domain = domain;
    }

    public Boolean IsUserBlacklisted(IsUserBlacklistedRequest request)
    {
        var subDomainToQuery = GetSubDomainToQuery(request);
        var fullDomainToQuery = String.Format("{0}.{1}", subDomainToQuery, _domain);

        var dnsRecords = _dnsService.GetRecords(fullDomainToQuery);
        if (dnsRecords != null && dnsRecords.Any())
        {
            // Match between records and user information
            // Note: I know I shouldn't write pseudo-code, but this part
            // is really unrelevant to the question
        }

        // If no DNS records, assume the user is not blacklisted
        return false;
    }

    private String GetSubDomainToQuery(IsUserBlacklistedRequest request)
    {
        return String.Concat(
            request.FirstName,
            request.LastName,
            request.BirthDate.ToString("yyyyMMdd")
        );
    }
}

Note: This post has been copied from this StackOverflow topic

public interface IUserBlacklistService
{
    Boolean IsUserBlacklisted(IsUserBlacklistedRequest request);
}

public class IsUserBlacklistedRequest
{
    // Properties representing necessary data to determine if the
    // user is blacklisted
}
public interface IDnsService
{
    IEnumerable<DnsRecord> GetRecords(String queriedDomain);
}

Note: This post has been copied from this StackOverflow topic Edit: Made the code more real so the question can be replied to. Sorry, everyone.

public interface IUserBlacklistService
{
    Boolean IsUserBlacklisted(IsUserBlacklistedRequest request);
}

public class IsUserBlacklistedRequest
{
    public String FirstName
    {
        get;
        set;
    }

    public String LastName
    {
        get;
        set;
    }

    public DateTime BirthDate
    {
        get;
        set;
    }

    public String BirthCity
    {
        get;
        set;
    }

    public String BirthCountry
    {
        get;
        set;
    } 

    public String BirthDepartment
    {
        get;
        set;
    }
}
public interface IDnsService
{
    IEnumerable<String> GetRecords(String queriedDomain);
}

So the class DnsUserBlacklistService would look like this:

public class DnsUserBlacklistService: IDnsUserBlacklistService
{
    private readonly IDnsService _dnsService;
    private readonly String _domain;

    public DnsUserBlacklistService(IDnsService dnservice, String domain)
    {
        _dnsService = dnsService;
        _domain = domain;
    }

    public Boolean IsUserBlacklisted(IsUserBlacklistedRequest request)
    {
        var subDomainToQuery = GetSubDomainToQuery(request);
        var fullDomainToQuery = String.Format("{0}.{1}", subDomainToQuery, _domain);

        var dnsRecords = _dnsService.GetRecords(fullDomainToQuery);
        if (dnsRecords != null && dnsRecords.Any())
        {
            // Match between records and user information
            // Note: I know I shouldn't write pseudo-code, but this part
            // is really unrelevant to the question
        }

        // If no DNS records, assume the user is not blacklisted
        return false;
    }

    private String GetSubDomainToQuery(IsUserBlacklistedRequest request)
    {
        return String.Concat(
            request.FirstName,
            request.LastName,
            request.BirthDate.ToString("yyyyMMdd")
        );
    }
}
Post Closed as "Not suitable for this site" by RubberDuck, Vogel612, Kid Diamond, Mathieu Guindon, amon
Source Link
Loading