Java: static abstract (again) - best practice how to work around

后端 未结 9 1118
误落风尘
误落风尘 2021-02-01 16:30

I theoretically understand the point why there is no abstract static in Java, as explained for instance in Why can't static methods be abstract in

9条回答
  •  太阳男子
    2021-02-01 17:05

    The question is not clear enough to provide an objective answer. Since I cannot give you a fish, this answer is more on the lines of "Teach you to fish"

    When faced with design issues like these where you think "duh..now sure why such a simple thing is so hard" more often than not, you are either designing it blatantly wrong or you are over complicating things. If I am empathizing correctly, the design issue seems like a "common requirement" yet the language is not allowing it.

    • Trace back your design steps/decisions
    • question all the "obvious" and "off course" you are basing your design on (you are using quite a few of them above)
    • see if things can be simplified (don't take any of the OO concepts to its extreme. Make compromises based on ROI)

    ...and you will most likely arrive at an acceptable answer.

    If you still don't, post back the classes and interfaces you think you want (with compile errors since language is not allowing certain things) and maybe we can help you tune your design.

提交回复
热议问题