The finalFunctionsMeta module

The finalFunctionsMeta module contians classes which provide the ability to declare specific functions of a class to be ‘final’, which means that an Exception will be raised in the event that a subclass tries to override the functionality of those functions.

Here is an example of using the classes in this module:

# First define the metaclass that defines the list of final functions
class FinalMeta(FinalFunctionsMeta):
    finalFunctions = ["__del__"]

# Now define the base class which forces all child classes to use the
# correct metaclass
class Parent(FinalFunctionsParentBase):
    requiredMetaclass = FinalMeta

    def __init__(self):
        FinalFunctionsParentBase.__init__(self)

# Finally, define the child class and override a few of the
# parents functions
class Child(Parent):
    __metaclass__ = FinalMeta

    # This function can be overridden
    def __init__(self):
        Parent.__init__(self)

    # This function CANNOT be overridden
    def __del__(self):
        Parent.__del__(self)

# This will throw an Exception indicating that __del__ cannot be
# overridden by the Child class!
c = Child()

The RequiredProperties class

Inheritance diagram of pyamp.patterns.interfaces.finalFunctionsMeta.RequiredProperties

class pyamp.patterns.interfaces.finalFunctionsMeta.RequiredProperties

The RequiredProperties class provides an interface which allows subclasses to define a set of properties that must be defined for that class.

This class checks that all of those properties are defined, and if one of them is not defined this class throws an exception.

Check that all the required properties are defined.

classmethod checkRequiredProperties(obj)

The FinalFunctionsParentBase class

Inheritance diagram of pyamp.patterns.interfaces.finalFunctionsMeta.FinalFunctionsParentBase

class pyamp.patterns.interfaces.finalFunctionsMeta.FinalFunctionsParentBase[source]

The FinalFunctionsParentBase provides a base class which provides the ability to define final functions in the base class. This will prevent any subclasses from overloading these specific, i.e., final, functions.

This class provides the ability to specify the specific metaclass that must be defined for all subclasses of this base class. The metaclass chosen should be a subclass of the FinalFunctionsMeta metaclass which defines the list of final functions and keeps them from being overridden.

Create the FinalFunctionsParentBase class.

The FinalFunctionsMeta class

Inheritance diagram of pyamp.patterns.interfaces.finalFunctionsMeta.FinalFunctionsMeta

class pyamp.patterns.interfaces.finalFunctionsMeta.FinalFunctionsMeta[source]

The FinalFunctionMeta class is a metaclass which provides the ability to define a list of functions that should not be allowed to be overridden by classes which use this metaclass.

Table Of Contents

Previous topic

The interfaces module

Next topic

The requiredProperties module

This Page