inheritance - Strange interface design Java -
at work came across following design in java project:
consider interfaces foo
, bar
, , baz
follows:
interface bar { public int a(); }
interface baz { public int b(); }
interface foo extends bar, baz { public int c(); }
now, consider class fooimpl
:
public class fooimpl implements foo { private bar bar; private baz baz; public int a() { return bar.a(); } public int b() { return baz.b(); } public int c() { return 0; } }
what use cases kind of class hierarchy? seems me introduces lot of boilerplate , not add in terms of abstraction, other breaking large file smaller files.
it allows things this:
foo foo = new fooimpl(); usebar(foo); public void usebar(bar bar) { bar.a(); }
whether useful depends on real context. example code classes , methods meaningless names not support rational judgement.
the other thing note fooimpl
implemented kind of wrapper bar
, baz
instances. that's not (strictly speaking) interface design issue.
Comments
Post a Comment