Restrict inheritance to desired number of classes at compile-time

前端 未结 4 1619
野趣味
野趣味 2021-01-01 06:55

We have a restriction that a class cannot act as a base-class for more than 7 classes. Is there a way to enforce the above rule at compile-time?

I am aware of Andre

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 07:30

    Lots of the various static code analysis tools provide information about inheritance hierarchy. Rather than try and handle it in your code, I would look into a tool that could set up some rules for inheritance hierarchy and fail the build if those rules are not followed. Might cost a little $ and you might have to write a custom rule (I've seen inheritance depth, but not inheritance "breadth" like you want). But, in the long run, I think that's your best bet.

    Per comment: I've used Coverity with some success. Bit spendy. There are several good SO threads that may have better options.

提交回复
热议问题