Design question - user data from two different sources


#1

hello,

how would you go about this: I would like my app to be able to
alternatively draw user data from two sources - a users table in a
database and an LDAP server. By alternatively I mean it would be set up
to draw from one of these sources, not both at the same time. I would
like to have objects of type Person which I would use regardless of
where this person is stored, so both the active record model and the
ldap user model would have a common set of functions that they would be
responding to and the application can ignore where the data is pulled
from.

so what would be an elegant way of achieving this? I would appreciate a
suggestion of some pattern of organising these models. What I’ve come up
with so far are 3 classes - DbPerson and LDAPPerson, and a Person class
which is supposed to be something like an interface. It has an if clause
that checks the USE_LDAP constant. Depending on this test it sets a
@my_class variable. Then it defines wrappers to all the common functions
of the two models and calls the methods of the relevant model by using
the @my_class var. This works but it seems clumsy to me so I’m looking
for insights :slight_smile:

Thanks!


Agnieszka