Я разрабатываю API в Python. API имеет две версии, разные версии имеют некоторые различия для каждого API.
class Client:
def __init__(self, username, password, version):
pass
class ClientV2:
def __init__(self, username, password):
pass
def jobs():
pass
def model():
# V3 doesn't have this method.
pass
class ClientV3:
def __init__(self, username, password):
pass
def jobs():
# the logic is different from V2
pass
То, что я ищу, выглядит так:
client = Client('user', 'passwd', 3)
# if the version = 3, then the client object will be ClientV3 actually.
# if the version = 2, then the client object will be ClientV2 actually.
Существует ли типичный объектно-ориентированный дизайн за это в Python?
Спасибо за любые предложения, спасибо.