2 classes implement same interface, duplicated code

.net, c#, interface, oop

Solution

Yes. You can.

public abstract class BaseUser : IUser
{

}

public class User : BaseUser 
{

}

public class AdminUser : BaseUser
{

}

Problem

I have an interface: ``` public interface IUser { } ``` And then 2 classes that implement this interface: ``` public class User : IUser { } public class AdminUser : IUser { } ``` Now the problem I see is that there is duplicate code between User and AdminUser when implementing a method in the interface. Can I introduce an abstract class that would implement the common code between User and AdminUser somehow? I don't want AdminUser to inherit from User.

Original source