I have an app in Django that expects to get a record with the fields email, first_name, and last_name.
However, sometimes I want to be able to send it something that isn't actually a record but behaves like one (in that it has the necessary fields as attributes), like so:
class FakeRecord(object): def __init__(self, email, first_name=None, last_name=None): self.email = email self.first_name = first_name self.last_name = last_name
I'm wondering if there is a standard name for this kind of object or if
FakeRecord works as the name for this class.
More generally, is there a name for a class that stands in for or behaves similarly to another class? Is there a standard implementation/design pattern?
For the purposes of my app, basically I have a utility function that sends an email to a recipient. The recipient can be any Django record so long as it has an email address, a first name, and a last name.
However, sometimes the app sends a one-off mailing to some given e-mail address that doesn't have a record. In those cases, I simply create a FakeRecord with the email address (and first name/last name if available), and send that in instead.
Since the utility function itself doesn't do anything with the record other than retrieving the attributes, none of the other db functionality of a Django record object is needed.