Next / Previous / Contents / Shipman's homepage

26. class AbBind: Base class for bindings

See the discussion of symbol table entries and bindings in Section 25, “class AbSym: One symbol table entry”.

nomcompile3
# - - - - -   c l a s s   A b B i n d

class AbBind(object):
    '''Base class for symbol table bindings.

      Exports:
        AbBind ( abbr ):
          [ abbr is a stripped, uppercased bird code ->
              return a new AbBind instance for code (abbr) ]
        .abbr:       [ as passed to constructor, read-only ]

      Virtual methods, must be provided by derived classes:
        .__str__(self):
          [ return a string representation of self ]
        .combine ( other ):
          [ other is an instance of AbBind ->
              if self and other can be combined ->
                return a new AbBind instance representing
                that combination
              else -> raise ValueError ]
        .lookup():
          [ if self is associated with a specific taxon ->
              return a Taxon instance representing that taxon
            else -> return None ]
        .eng():
          [ if self describes a binding based on an English
            name ->
              return that name as a string
            else -> return None ]
        .writeFlat ( outFile ):
          [ (outFile is a writeable file) and
            (self is associated with a specific taxon) and
            (self describes a binding based on an English
            name ->
              outFile  +:=  an abbreviations file flat record
        .writeXML ( parent ):
          [ parent is an et.Element ->
              parent  :=  parent with a new child node added
                          representing self ]
    '''

Following good Python practice, we define the virtual methods so that they will raise NotImplementError if a derived class fails to override them.

nomcompile3
    def __str__ ( self ):
        raise NotImplementedError("Classes derived from AbBind must "
            "override the __str__() method.")

    def combine ( self, other ):
        raise NotImplementedError("Classes derived from AbBind must "
            "override the combine() method.")

    def lookup ( self ):
        raise NotImplementedError("Classes derived from AbBind must "
            "override the lookup() method.")

    def eng ( self ):
        raise NotImplementedError("Classes derived from AbBind must "
            "override the eng() method.")

    def writeXML ( self, parent ):
        raise NotImplementedError("Classes derived from AbBind must "
            "override the writeXML() method.")