4 Defining Static Methods

For static methods, you define your method as such:

def static_mymethodname(self, ...whatever...):

The static_ prefix says "this is a static method". The self argument will point to the data class itself, not an instance of the dataclass. In the case that you want to call a super classes static method on the current subclass, and in the context of the subclass, you say:

   fooresult = MySuperClass.static_barmethod(self, baz, fred, barney)

This is useful when you are overloading a static method in a subclass but still want to call the superclass version (such as new). This is very much unlike Java, which disallows this. (don't know about C++)

Your newly-defined method can then be called as

SomeClass.mymethodname(...whatever...) without the static_ prefix to call the method statically. For example, the call to the new method on the Users object towards the beginning of this document is a static call (it's defined as static_new in the PyDO base class).

NOTE: you cannot override a static method with an instance method or vice versa.

Why this is useful is this: You want to make it so that you don't have to specify the CREATED and LAST_MOD fields when making a call to new since the caller shouldn't really have to care and it can be taken care of automatically. You can, if you want to, enforce what fields they can or must set on a call to new. For example: setting the CREATED and LAST_MOD automatically and enforcing that USERNAME and PASSWORD only are specified.

    def static_new(self, refetch = None, USERNAME, PASSWORD):
        return PyDO.static_new(self, refetch, USERNAME=USERNAME, 
                               PASSWORD=PASSWORD, CREATED=SYSDATE, 
                               LAST_MOD=SYSDATE)

MAKE SURE TO USE THE STATIC UNBOUND VERSION WHEN CALLING YOUR SUPERCLASS OR THE WRONG THINGS WILL LIKELY HAPPEN!

In the cases where PyDO is not your direct superclass, you might call your superclass' static_new method instead. On the other hand, you may want to handle the new method entirely yourself.