The interface module

The interface module provides a base class which provides a function to decorate functions in order to label specific functions as interface functions.

The PassThrough' class is an implementation of the :class:`Interface class which provides the ability to connect a child PassThrough object to a parent PassThrough object so that any time the child’s interface functions are called, the call is instead redirected to the parent’s function of the same name.

The Interface class

Inheritance diagram of pyamp.patterns.interfaces.interface.Interface

class pyamp.patterns.interfaces.interface.Interface[source]

The Interface class provides to ability to identify specific class functions to be ‘interface’ functions.

This class contains a class property called InterfaceProperty which defines the name of the property used to identify interface functions.

This class provides a interface() function which uses the InterfaceProperty property to create an implementation specific decorator which can be used to decorate functions that should identified as interface functions.

Example:

class Example(Interface):
    InterfaceProperty = "ExampleInterfaceProperty"

    @Example.interface
    def testPrint(self, message):
        print "Message:", message

This the above example the testPrint() function has been decorated and is thus an interface function.

connect(parent)[source]

Connect to a parent’s interface methods.

Note: This should be overriden by concrete Interfaces

  • parent – The parent interface object
getInterfaceFunctions()[source]

Get a dictionary of the interface function names mapped to the actual functions.

classmethod interface(function)[source]

A decorator for functions to make them interface functions for this Interface instance.

  • function – The function to decorate
classmethod isInterface(obj)[source]

Determine if the given object is an instance of the interface.

  • obj – The object

The PassThrough class

Inheritance diagram of pyamp.patterns.interfaces.interface.PassThrough

class pyamp.patterns.interfaces.interface.PassThrough[source]

The PassThrough Interface provides the ability for a child PassThrough object to connect functions of the same name to the parent’s Interface functions.

When a child class connects to the parent’s interface functions, all calls to the child’s interface functions are instead redirected to the parent’s functions of the same name.

Example:

class Parent(PassThrough):
    @PassThrough.interface
    def testPrint(self, message):
        print "Parent message:", message

class Child(PassThrough):
    pass

parent = Parent()
child = Child()
child.connect(parent)

# Prints:
#    "Parent message:", this is a message
child.testPrint("this is a message")
connect(parent)[source]

Connect the child to the parent’s interface functions.

  • parent – The parent Interface

Table Of Contents

Previous topic

The requiredProperties module

Next topic

The borg module

This Page