Avoiding circular references: forward declaration isn't valid if I need objets's methods? -
i have large project, , got myself circular reference don't know how fix. have read forward declarations, if have understood well, object's public methods/data aren't public if use forward declaration.
i understand best way fix design program right first lines of code, inherit large code carries these kind of problems , add simple feature code find mess.
so... there other way of solving problem?
where class uses class b none of it's methods, class can forward declare class b. if class b uses class a, forward declaration remove half of cyclic dependency, @ least far compiler concerned.
if needs more intimate knowledge of b name, use interface (abstract class) invert dependency b. i.e. uses new c (instead of b) exports @ least interface requires, , b implements/extends c.
i've seen used reduce compilation times - reason asking, or more "good" design?
Comments
Post a Comment