Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Count how many classes you have with only one method and no data in them.

I have never done this, but for the usecase that you have mentioned, would the following work?

  class Xyz {
    private Type type;

    private RetType type1MethodName(params) {
      // Do Whatever
    }

    private RetType type2MethodName(params) {
      // Do Whatever
    }

    public Xyz(type) {
      this.type = type;
    }

    public RetType methodName(params) {
      switch(type) {
        type1:
          return type1MethodName(params);
        type2:
          return type2MethodName(params);
      }
    }
    
    public enum Type {
      type1;
      type2;
    }
  }
And then when we want to pass methods according to types, we can just instantiate the class with a proper type and pass it.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: