[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PGObject derived classes & constructors

Hi Chris,

Could you help me with the following: our API for PGObject-based classes has only one constructor (the regular 'new' constructor). Many (but not all) classes can be passed a single 'id' value. The constructed object sometimes has a 'get' method.
In some cases, this 'get' method returns a new instance, in other cases, the getter initializes fields in the 'current' instance.

I'm thinking:
 * The fact that the getter sets up the current instance makes me want
    to use the getter with the 'primary key' (id) to retrieve the object from
    the database. However, this means we can't require any fields in the
 * If the 'get()' method would be a class-level constructor (like new), always
   returning a new instance, we could start requiring fields in our classes
   (because the getter will make sure that required values are retrieved from
   the database before the field checks happen)

Would it be an idea to require a minimum number of methods and class methods to be implemented on a LedgerSMB::PGObject, like the ones above, but maybe also "save", "remove" (not delete, as that's a reserved word in Perl), ... (any others?)

The API for the getter would include some kind of database connection as the argument, as well as a hash (to request a single object) or an array of hashes (to request multiple objects).

Do you have any input on the matter?




http://efficito.com -- Hosted accounting and ERP.
Robust and Flexible. No vendor lock-in.
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
Ledger-smb-devel mailing list