design - How to keep a clean Java API -
design - How to keep a clean Java API -
i'm trying design java api this:
package core; public abstract class graphnode { public void add(condition... conditions) { // check conditions isn't null, , translate them map this.addcore(translatedconditions, new traversalcontext()); } protected abstract void addcore(map<string, condition> conditions, traversalcontext traversalcontext); }
the problem need concrete implementations able recursively pass command onto subsequent nodes in graph. this:
package core.nodes; public final class concretegraphnode extends graphnode { @override protected void addcore(map<string, condition> conditions, traversalcontext traversalcontext) { if (conditions.size() == 0) { // recursion done return; } // remove appropriate condition, modify traversal context, create or find next node in graph // pass phone call on recursively nextnode.addcore(conditions, traversalcontext); } }
my motivation here threefold:
incur cost of argument checking 1 time when called via public api. thenceforth, recursion happens against non-public apis, argument validation can skipped (or asserted). enable non-public api take context parameter has no business beingness in public api because it's implementation detail. include minimal abstraction types incore
package, separate bundle (core.nodes
) actual implementations of abstractions. however, java's accessibility modifiers don't seem accommodate this. beingness in separate package, can no longer phone call protected
members declared superclass. in other words, phone call nextnode.addcore
in concretegraphnode
not possible.
i'm wondering whether there's elegant way around doesn't require me move implementation classes core
package?
java design
Comments
Post a Comment