Interfaces Limit

Monkey Forums/Monkey Programming/Interfaces Limit

Rhodesy(Posted 2012) [#1]
Does anyone know if there is a limit as to how many interfaces a class can implement? or any advice on how many one should use in practice?

Are there any downsides in using a large number, say 20+ ?


Goodlookinguy(Posted 2012) [#2]
There is a limit, but it's near impossible to reach. In Java it's 65536 for instance. However, if you find yourself with 20+ interfaces on a single class you should probably think about refactoring your code because it sounds like you're designing something to do too much or giving it too many structures which should be compressed into a smaller number of interfaces. I don't think I've ever needed more than 5 interfaces per a single class. I'm not saying that you should limit yourself to 5 or 20 necessarily, but the code will be hard to maintain if you're designing it like that.


TheRedFox(Posted 2012) [#3]
Speaking of which, can't we have Traits in Monkey?


Tibit(Posted 2012) [#4]
You can always have one interface that implements other interfaces - in that way you can make it simple in your code.

Large number of interfaces can be handy - if you know what you are doing.

TheRedFox, could you explain what you mean by Traits?