which 1 better practice, doing this
public class { private b b; public a() { b = new b(this); } } public class b { private a; public b(a a) { this.a = a; } } or extending class, im confused difference besides having 'a' field.
it depends on particular situation.
lets assume a class represents car,
if b engine should use composition (car has engine)
if b racecar should use inheritance (racecar better car)
if in doubt, current trend in software development prefer composition on inheritance.
Comments
Post a Comment