Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redundant inheritance?

Tags:

c#

inheritance

Consider that classes

public class Category { }
public class Product { }

public interface IService<T> { }
public class ServiceBase<T> : IService<T> { }

public class CategoryService : ServiceBase<Category> { }
public class ProductService : ServiceBase<Product>, IService<Product> { }

Is inheritances of ProductService redundant? Just ServiceBase<Product> is enough?

I just made tests like this

static void Main(string[] args) {
    Console.WriteLine("CategoryService interfaces:");
    foreach(var item in typeof(CategoryService).GetInterfaces()) {
        Console.WriteLine(item.Name);
    }

    Console.WriteLine("ProductService interfaces:");
    foreach(var item in typeof(ProductService).GetInterfaces()) {
        Console.WriteLine(item.Name);
    }

    Console.ReadKey();
}

output

CategoryService interfaces:
IService`1
ProductService interfaces:
IService`1
like image 257
Kim Tranjan Avatar asked Feb 21 '26 12:02

Kim Tranjan


1 Answers

Yes it's redundant.

You can remove it and ProductService will still implement IService<Product>

like image 129
digEmAll Avatar answered Feb 24 '26 15:02

digEmAll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!