c# - Heirarchical nested generic interfaces -
i have chain of hierarchically nested generic interfaces, examples sake this:
icar<twheels, tbolts> twheels : iwheels<tbolts> tbolts : ibolts { ienumerable<twheels> wheels { get; set; } } iwheels<tbolts> tbolts : ibolts { ienumerable<tbolts> wheels { get; set; } } ibolts { }
is sensible way of handling these generic interfaces?
it makes defining methods this:
public tcar getcar<twheels, tbolts>(int id) tcar : icar<twheels, tbolts> twheels : iwheels<tbolts> tbolts : ibolts { ... }
is there way reduce code signature?
generics in c# should used avoid problems you've faced. i'd recommend revise interfaces hierarchy , throw generics away:
interface icar { ienumerable<iwheel> wheels { get; set; } } interface iwheel { ienumerable<ibolt> bolts { get; set; } } interface ibolt { }
then great @ use-cases, interfaces participate.
may be, there rare cases, when you'll need ir16wheel
instead of iwheel
, , type casting enough.
may be, enough pair non-generic interfaces generic ones:
interface iwheel<tbolt> : iwheel tbolt : ibolt { ienumerable<tbolt> bolts { get; set; } }
and use non-generics methods this:
public icar getcar(int id) { }
but use generics in more specific cases.
Comments
Post a Comment