• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 6. An Introduction to Interfaces > Advanced Usages of Interfaces

Advanced Usages of Interfaces

When you have Python-based interfaces, many new possibilities develop. You can use interfaces as objects that can define contracts. For example, you can say that there is a class AllText that converts IExample to IAllText, where the latter interface has a method getAllText() that returns all human-readable text from IExample. Such a class is known as an adapter. More formally, adapters use one interface (for example, IExample) to provide another interface (for example, IAllText).

Even more commonly, interfaces are used for identification. Zope 3's utility registry often executes queries in the form “Give me all utilities that implement interface I1.” Interfaces are even used to classify other interfaces. For example, you might declare your IExample interface to be an IContentType. You can then go to the utility registry and say, “Give me all interfaces that represent a content type (IContentType).” When you know these content type interfaces, you can figure out which classes are content types.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint