c# - How can we avoid redundant interface implementation? -


i have design question. shall present hypothetical situation. have couple of interfaces required application make object usable. let’s are;

1.  iadult.cs, 2 properties   a.    age   b.    licenceno. 2.  ieducated.cs, 2 methods   a.    read()   b.    write() 

let’s assume implementation of these interfaces shall remain same of times. so, if had implement abstract class out of these interfaces, create class, say, abstract class educatedadult { }. define 3 different classes respective inheritances , set of respective properties;

1.  carpenter.cs (derives class a) 2.  plumber.cs (derives class b) 3.  programmer.cs (derives class c) 

here, classes a, b, c part of external libraries cannot edit. make these objects usable in program, need implement above given interfaces. issue each 1 of these classes, i’ll have explicitly implement above stated interfaces. there better design not have implement interfaces redundantly in classes. solution, had been possible;

class educatedadult<t>: t, iadult, ieducated { <implementation of interfaces> } , later, maybe, initialize derived classes like;

carpenter carpenter = new educatedadult<carpenter>(). not ideal solution, ‘cause public interface of carpenter object shall still not include interface members (without required casting). then, suitable design?

you can't provide default implementations interfaces in .net implementing class provide implementation, can fake using extension methods on interfaces.


Comments