I have a C# interface, and a concrete class that implements that interface. I now want to create another class that implements that interface. Simple enough.
However, most methods will be exactly the same in the classes, and only a couple of methods will actually change.
I don’t want to duplicate all of the logic in my 2nd class that is contained in my first.
How do I create the 2nd class, and use the logic in my first class except for the extra stuff?
My interface is called IEventRepository, and my 1st class is called BaseEvents. I now want to create a new class called FooBarEvents.
My class definition for FooBarEvents is:
public class FooBarEvents : BaseEvents, IEventRepository
My intention was to then use the return base.Method() in each method that duplicates the code.
I’m assuming this isn’t correct?
FooBarEventsshould only need to inherit fromBaseEvents, not also implementIEventRepository, asBaseEventsalready implements the interface. If you need to change the behavior of someIEventRepositorymethods inFooBarEvents, just override those methods.Edit: some examples