How can I reduce the Cyclomatic Complexity of this?

前端 未结 5 966
情深已故
情深已故 2020-12-16 13:37

I have a method that receives an Object and does something based on what type of object it detects:

void receive(Object object) {
    if (object instanceof O         


        
5条回答
  •  伪装坚强ぢ
    2020-12-16 14:03

    Can't you leverage an object-oriented approach for this? Create an interface that has the doSomething() method then create subclasses that implement the desired behavior? Then calling object.doSomething() would execute the appropriate behavior?

提交回复
热议问题