[Zope-dev] Intializing the objectsformerly-known-as-RackMountables

Itamar Shtull-Trauring itamar@maxnm.com
Wed, 19 Jul 2000 17:41:19 +0300


"Phillip J. Eby" wrote:

> >Doing self.__dict__['name'] = 'Rincewind' seems kinda ugly.  Maybe newItem
> >should by default call a function on newly created objects, say __init?  I
> >don't want to have to subclass Specialist (or in my case, LoginManager) each
> >time I want to this, since it's a *very* common action.  For example,
> 
> Could you give a more specific example?  My assumption is that if you need
> to have things happen upon adding, that one uses a trigger to do it.  Or,
> if the data is specific to that instance, then the appropriate thing would
> be to manipulate properties or attributes in the code that calls newItem().

I like the OO idea that changes to an object should be done by the object,
not by someone else.  It seems silly to have to write a trigger to do this,
or a factory.  Why do classes have __init__ anyway?  So that all the
internal object creation logic is in the same place.

Okay - this is the ASP Account class.  These are user objects that I'd like
to store in a regular LoginManager.  I could subclass LoginManager of
course, but I don't want to spread my code all over the place, when there's
no real need.

class ASPAccount(LoginUser, MemberMixin):

    def __init__(self, id, title=''):
        LoginUser.__init__(self, id)
        self.__dict__['_currentPayment'] = None
        self.__dict__['debt'] = Payment.Debt(0.0)
        self.__dict__['debtInPayment'] = Payment.Debt(0.0)
        self.__dict__['services'] = ServicesManager.ServicesManager()
        self.__dict__['lastMonthlyPayDay'] = None
        # day in month on which we pay
        self.__dict__['payday'] = 15
        self.__dict__['log'] = ""


> Also, it isn't necessary to subclass the specialist -- you don't have to
> call your routine newItem(), after all.  newUser() would be a better choice
> of name for the method, it sounds like.

Again, why should I fagment my class into multiple parts?  I want it all to
be in once place - it's more readable, easier to debug, easier to
understand, and more portable.

-- 
Itamar S.T.  itamar@maxnm.com
Fingerprint = D365 7BE8 B81E 2B18 6534  025E D0E7 92DB E441 411C