How to build an hierarchy tree of categories in java using enums or any other way?

前端 未结 3 1930
借酒劲吻你
借酒劲吻你 2021-01-03 10:35

Assuming that we have a set of categories: categories={A,B}. Let\'s assume more that A consists of subcategories: {A1,A2,A3} and B consists of subcategories: {B1,B2}.In addi

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-03 10:56

    Probably an implementation of this:

    public interface Category {
        String getName();
        Category getParent();
        List getSiblings();
        List getChildren();
        List getDescendants();
        void addChild(Category category);
        void addChildren(List categories);
    }
    

提交回复
热议问题