Is it considered useful to let the class know about this type?

I have the following interface:

public enum AggregatorType{
    DATA_BASE,
    GLOBAL_CACHE,
    //etc
}

public interface DataAggregator<T>{

     public AggregatorType getType();

     public Collection<T> getData();

}

My question is to put different types in the same enumeration. For me, it smells at least unimportant (because two separate types are placed in the same place). But I don’t see what potential problems this could lead to. Could you help me understand?

+4
source share
1 answer

Typically, using types is enumnot good practice to explicitly determine the type of a class, because in some other part of your code you want to have a control structure (if-else / switch-case) of that type to separate the aggregation method.

, aggregate, . DataBaseAggregator CacheAggregator , .

+3

Source: https://habr.com/ru/post/1599830/


All Articles