How can one describe a rock-paper-scissors relationship between 3 items?

后端 未结 3 1218
深忆病人
深忆病人 2021-01-04 09:19

Let\'s say I have the following structure:

abstract class Hand {}

class Rock extends Hand {}
class Paper extends Hand {}
class Scissors extends Hand {}
         


        
3条回答
  •  天涯浪人
    2021-01-04 10:01

    How about this?

    class Scissors extends Hand implements Beats {}
    

    where Beats<> is a generic interface whose signature looks like:

    interface Beats {}
    

提交回复
热议问题