在浏览一个项目的代码时,我遇到了一个实现,BinaryHeap
其中两个实现(使用 Array 和 Tree)被打包在接口本身中。我发现它有些复杂。代码是:
public interface BinaryHeap<T extends Comparable<T>> extends IHeap<T> {
//some variables and other declarations.
public static class BinaryHeapArray<T extends Comparable<T>> implements BinaryHeap<T> {
//Implementation based on Array
}
public static class BinaryHeapTree<T extends Comparable<T>> implements BinaryHeap<T> {
//Implementation based on Tree
}
}
这种方法有什么问题吗?在可读性方面如何改进?