I am trying to implement a class with the best and safest conventions possible. Are there better ways to
a) prevent external edits to properties, and
b) enforce certain constraints, such as valid rank and suit, on these properties?
class Card:
__ranks = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']
__suits = ['Heart', 'Club', 'Diamond', 'Spade']
def __init__(self, rank, suit):
assert rank in self.__ranks
assert suit in self.__suits
self.__rank = rank
self.__suit = suit
def getRank(self):
return self.__rank
def getSuit(self):
return self.__suit