I think you are looking for a strategy template . The way to do this is not Java specific or other "cool stuff" on this subject. These types of things are transcend .
, BfsStrategy DfsStrategy. , . , , . ( /, , .)
:
public final class Seeker<E, K> {
private final E structure;
private final SearchStrategy strategy;
public Seeker(final E aStructure, final SearchStrategy aStrategy) {
structure = aStructure;
strategy = aStrategy;
}
public boolean search(K aKey) {
return strategy.search(structure, key);
}
}