The best way to modified Interface

Right now I already have an Interface for my data access repository that looks like this :

public interface IRepository<out T> where T: IDatabaseTable
    // Properties
    string[] DefaultFields { get; }

    // Methods
    IGetResult<T> GetList(SearchCriteria criteria);
    IResult<T> GetItem(String accountId, long id);
    IResult<long> CreateItem(CommonField field, IContent content);
    IResult<long?> UpdateItem(CommonField field, long id, IContent content);
    IResult<int> DeleteItem(CommonField field, long id);

This interface has inherited by 1 BaseClass and there are 6 other class that inherited from the BaseClass. Now I want to create a new class that also implement this interface but for GetItem method I only need accountId parameter in it.

This is the GetItem method on my BaseClass that used by 6 other class

public virtual IResult<T> GetItem(String accountName, long id)
        if (id <= 0) return null;

        SqlBuilder builder = new SqlBuilder();
        var query = builder.AddTemplate("SELECT /**select**/ /**from**/ /**where**/");

        builder.Select(typeof(T).GetProperties().Where(p => p.CustomAttributes.All(a => a.AttributeType != typeof(SqlMapperExtensions.DapperIgnore))).Select(p => p.Name).ToList());
        builder.Where("id = @id", new { id });
        builder.Where("accountID = @accountID", new { accountID = accountName });
        builder.Where("state != 'DELETED'");

        var result = new Result<T>();
        var queryResult = sqlConn.Query<T>(query.RawSql, query.Parameters);

        if (queryResult == null || !queryResult.Any())
            result.Message = "No Data Found";
            return result;

        result = new Result<T>(queryResult.ElementAt(0));
        return result;

What is the best way to implement this requirement. Should I create a new interface just for that one class or is there any other way I can do it better?

Thanks for all of the response and feedback to my questions.

Source: oop

Leave a Reply