Quirky question:
Imagine that I have a base class called BaseFoo. I have an interface with some methods called IFoo. And I have tons of classes beneath BaseFoo.
If i implement the interface in BaseFoo, i dont need to implement in the inherited classes, correct?
Ok, but imagine that i have a generic function that will treat IFoo’s. Do i need to explicitely declare that they implement IFoo?
Like this (pseudo-illustrational-code)
public class BaseFoo:IFoo;
public interface IFoo;
Should i do this?
public class AmbarFoo:BaseFoo,IFoo
or?
public class AmbarFoo:BaseFoo
What is the most correct way? Are the effects the same? If i test if AmbarFoo is a IFoo what will I get?
Thanks
It will behave the same way regardless. You’d only need to restate the interface name if you wanted to reimplement the interface with explicit interface implementation. An instance of
AmbarFoowill indeed “say” that it implementsIFoo.