Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > 2f465c7af448b596f18821b95c37334d > files > 286

python-Traits-4.3.0-1.fc18.i686.rpm

#  Copyright (c) 2007, Enthought, Inc.
#  License: BSD Style.

# interface_implementation.py - Example of implementing an interface

#--[Imports]--------------------------------------------------------------------
from traits.api import HasTraits, implements, Str, Instance
from interface_definition import IName

#--[Code]-----------------------------------------------------------------------

class Person(HasTraits):
    implements(IName)

    first_name = Str( 'John' )
    last_name  = Str( 'Doe' )

    # Implementation of the 'IName' interface:
    def get_name ( self ):
        """ Returns the name of an object. """
        return ('%s %s' % ( self.first_name, self.last_name ))

#--[Example*]-------------------------------------------------------------------

class Apartment(HasTraits):
    renter = Instance(IName)
william = Person(first_name='William', last_name='Adams')
apt1 = Apartment( renter=william )
print 'Renter is: ', apt1.renter.get_name()
# Result: Renter is: William Adams