Does this facade code look like a good idea, or is there anything inherently flawed about the design? More importantly, is there a problem I will likely run into down the road with this code? Any help is much appreciated.
I'm trying to build this so that I can have a Payment class as my facade, which accepts cc numbers, etc. and a PayPal class as my implementation so that I can charge the card and store the info regarding that, etc.
class MyFacadeClass(models.Model):
account = models.ForeignKey('Account') # Account omitted from example for brevity.
implementation = CharField(max_length=255, choices=IMPL_CHOICES) # IMPL_CHOICES omitted for brevity
some_field = models.CharField(max_length=255)
def __init__(self, *args, **kwargs):
super(MyFacadeClass, self).__init__(*args, **kwargs)
if self.implementation == 'PAYPAL':
from somewhere import MyPayPalImplementationModelClass
self.impl = MyPayPalImplementationModelClass(my_facade_instance=self, some_field=self.some_field, account=self.account)
# Then MyPayPalImplementationModelClass does stuff with PayPal and has its own attributes such as ack, and datetime and fee_amount behind the scenes.
def save(self, force_insert=False, force_update=False)
if self.impl.is_valid():
self.impl.save()
super(MyFacadeClass, self).save(force_insert, force_update)