Abstract method with variable list of arguments

前端 未结 5 1359
轮回少年
轮回少年 2021-02-05 07:09

I haven\'t quite found an elegant way to solve this issue. I have an abstract class that several other classes are inheriting with an abstract method that can contain anywhere f

5条回答
  •  醉话见心
    2021-02-05 07:20

    The best approach I can think of is to group the items according to the behavior of their use() method.

    Example

    public abstract class QueueableItem {
        public abstract void use(String, Queue);
    }
    
    public abstract class OrdinaryItem{
        public abstract void use(String);
    }
    

    If the grouped items share a common behavior (common as in same method signature & return value), you can define and extend a parent class that will contain the definition of this common behavior.

提交回复
热议问题