I am working on a project to deve开发者_JAVA百科lop a poker bot, I have to store the state of every hand that is played. I wanted to do this via an object - however Players
can only read from the state and the Dealer
is allowed to write to the state. I thought a good way to solve this would be to make the HandState
object implement 2 interfaces (one for Players and one for the Dealer) however I am having trouble naming them as I cant think of logical names other than IHandState - is there some kind of convention to deal with these things? Has anyone experienced something similar?
Thanks
PlayerStateHandler
and DealerStateHandler
As a convention, my Interfaces either contain -er
or -able
PlayerActions
and DealerActions
or
PlayerAware
and DealerAware
What about DealerState
and PlayerState
?
To answer your problem, not your question: Prefer composition over inheritance (including of inheritance of interface).
Also I get the impression that you have poor encapsulation by using getters and setters, instead of meaningful operations. If you get improve the abstractions, things should become clearer.
You have one state object, name it's class HandState
.
Make it implement the two interfaces. Call them IWriteable
and IReadable
Then create the player, it has access to an object of type HandState
, however accesses it through the IReadable
interface. Similarly, the dealer, it accesses the HandState
through the IWriteable
Interface.
uasually interface will have an adjective names. so i prefer IStateable
精彩评论