SlideShare una empresa de Scribd logo
1 de 29
The ZCA   Building elegant things
Overview

• A real world problem.

• An explanation of the core ZCA concepts.

• A simple model of the problem to use during the talk.

• Code to apply concepts in the context of the simple
  model.
The Problem
Outline of the problem
which led me to
appreciate the ZCA
The newsletter problem

• Types designed for display on the web which we couldn't
  edit.

   • But which were in a good class hierarchy.

• But we need to reformat some of them for display in a
  newsletter—and format the rest in a generic manner.

• And, as always, we’re on a deadline.

• The ZCA can help us with this problem
A “standard”
A Typical Day
As Gregor Samsa awoke one morning from
                                                item just gets
uneasy dreams he found himself transformed      a title and
in his bed into a monstrous vermin. More...
                                                description.

Birthday News: “I feel no older”                A news item
         After celebrating his 27th birthday,   gets a picture
         a man claimed today to “feel no
         older” than the day before. More...    beside it.

Paris in the Autumn view the album              And for a
                                                photo album,
                                                why not just
                                                some photos?
Modelling the problem

• I’m going to use the problem I just described as a basis.

• We’re going to work through a simplified version to go
  over the primary concepts in the ZCA.

• First, let’s look at the concepts.
Core Concepts
Fire up your diggers
Let’s talk about Zope

• Zope = Zope Object Publishing Environment.

• Zope’s model is that of an object graph.

• Both content and functionality are stored in Zope’s object
  database (the ZODB).

• Zope 2 was a bit all or nothing: inventing wheels, very
  interwoven.
I <3 Zope




            http://bit.ly/dtbNqj
Zope 3

• Zope 3 was the reformulation of Zope into components.

• The ZCA was built to meld these components together
  into a web platform.

• It’s not crazy.
The ZCA
             • A Service Locator—it helps the parts of
               your application find each other without
               tight coupling.

             • Components are registered with a central
               registry, which responds to queries.

             • Configuration decides what component
               provides a given function.

             • Though it would be possible to write a
               plugin architecture for your project, the ZCA
               is already there and well tested.
We provide                                                       I need
function X                                                     function X
                               I can help
Interfaces

• Defines a set of functionality a thing promises to provide.

• A gentleman’s agreement, not a contract.

• Can be implemented any object, unlike some other
  languages.

• The core of the ZCA:

   • You can ask for an object which implements an interface;

   • Or an object to convert from one interface to another.
Interfaces


       ZODB


       LDAP                        User Code


      SQL DB                           isValidUser()
                                         addUser()
                                       removeUser()
               ISecurityProvider
Utilities

• A utility is an object which implements a specific interface.

• You register the object with the ZCA, telling the ZCA the
  object is a utility which implements the interface.

• Then ask for it later from anywhere in your program.
Utilities


            ZODB


            LDAP                       User Code


       SQL DB                              isValidUser()
                                             addUser()
                                           removeUser()
“implements”
                   ISecurityProvider
Adapters

• Adapters can convert from one or more interface to
  another.

• In Zope they are often used to add functionality in addition
  to just altering and interface.
Adapters



 SQL DB        Adapter                       User Code




                userIsOkay()
userIsOkay()
                                              isValidUser()
                isValidUser()                   addUser()
                                              removeUser()


                         ISecurityProvider
Multi-Adaptors

• Multi-adaptors adapt more than one input interface to a
  single output interface.

• Zope uses this for rendering pages by adapting as follows:


HTTP Request
                                                View
                           Adapter         (rendered page)
Content Item
Is this too far?

• Zope 3 uses multi-adaptors to register event handlers:
                             Like the snappily named
Event type is                IObjectModifiedEvent
 defined by
 Interface
                                            Callable which
                          Adapter
                                            handles event
Content Item
Work
     ed   Exam
                 ple
The simplified model

                         Finder
                    Selects items for
                        sending
 Content to
select from.                            IItemFinder




 Renderer for most items                               Rendering
                                                       “Pipeline”
 Renderer for news items


Renderer for photo albums


                             INewsletterItemRenderer
Content Objects


                  StandardItem




SubStandardItem       PhotoAlbum   NewsItem
The content objects
# Note they have no knowledge of the
# ZCA.


class StandardItem(object):              class NewsItem(StandardItem):

    def __init__(self, title):               def __init__(self, title,
        self.title = title               description, date):
                                                 self.title = title
    @property                                    self.description = description
    def url(self):                               self.date = date
        """Generate a url"""
        [...]



class SubStandardItem(StandardItem):     class PhotoAlbum(StandardItem):
    """This item should be renderable
by the adaptor for StandardItem"""           def __init__(self, title,
                                         thumbnails):
    def __init__(self, title):                   self.title = title
        self.title = "SUB! %s" % title           self.thumbnails = thumbnails
A utility to find them
class IItemFinder(Interface):
    def __call__():
        """Return a list of items which descend from StandardItem."""

class ItemFinder(object):
    implements(IItemFinder)
    def __call__(self):                             The ZCA bits
        """Hardcode for demo purposes"""
        return [
            PhotoAlbum("Crocodiles", []),
            StandardItem("A Standard Item"),
            SubStandardItem("A second standard item"),
            NewsItem("Man Feels No Different on Birthday",
                     """
                     Man reports feeling no different on 27th birthday
                     from the day before.""",
                     "10th July, 2010"),
            NewsItem("Less Newsworthy",
                     """
                     The world is going to end tomorrow at 14.27.""",
                     "13th June, 2010"),
            [... some more items ...]
        ]
Adaptors to render them
class INewsletterItemRenderer(Interface):
    def render():                           Our interface
        """Render an item"""

class BaseRenderer():
    """Base class to do what all the renderers need to do"""All renderers
    implements(INewsletterItemRenderer)
    def __init__(self, context):                            implement
        self.context = context

class BaseContentToNewsletterBlockRenderer(BaseRenderer):
                                                            the interface
    adapts(StandardItem)
    def render(self):                                       and adapt a
        return "*** %s (Standard Item)n    %s" % (
                self.context.title, self.context.url)       content item
class NewsItemToNewsletterBlockRenderer(BaseRenderer):      to it
    adapts(NewsItem)
    def render(self):
        return "*** %s (News)n    %sn    %snn    %s" % (
                self.context.title, self.context.date, self.context.url,
                [...format the body...]

class PhotoAlbumToNewsletterBlockRenderer(BaseRenderer):
    [...]
Register them
# These all use the Global registry. It's possible to
# have separate registries if needed for your application.
from zope.component import provideAdapter, provideUtility,
                           getUtility

# (1) A utility needs to be instantiated before registering.
provideUtility(ItemFinder(), IItemFinder)

# (2) Adaptors will be created as needed so don’t need
#     creating.
provideAdapter(BaseContentToNewsletterBlockRenderer,
                (StandardItem,),
                INewsletterItemRenderer)
provideAdapter(NewsItemToNewsletterBlockRenderer,
                (NewsItem,),
                INewsletterItemRenderer)
provideAdapter(PhotoAlbumToNewsletterBlockRenderer,
                (PhotoAlbum,),
                INewsletterItemRenderer)
And use them
Get the utility and call it to get item list:
finder = getUtility(IItemFinder)
items = finder()

The ZCA will find the right renderer:
body = "nn".join([
       INewsletterBlockRenderer(x).render() for x in finder ])

Let’s go!
print """
Dear subscriber,

%s

We hope you enjoyed this update,

The Team.
""" % body
Summary

• ZCA allows for building robustly componentised applications.

• Core is: Interfaces, Utilities and Adapters.

• It’s well tested and small enough to easily learn.

• It’s powerful enough for production use--and widely
  deployed.

• Suggested further reading:
  http://www.muthukadan.net/docs/zca.html
Get in contact:
                          mike@netsight.co.uk
Thank you for watching!   Or catch me in the hallways!

Más contenido relacionado

La actualidad más candente

Omnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the ThingsOmnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the ThingsJustin Edelson
 
Building DSLs With Eclipse
Building DSLs With EclipseBuilding DSLs With Eclipse
Building DSLs With EclipsePeter Friese
 
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)Chris Adamson
 

La actualidad más candente (6)

Real World MVC
Real World MVCReal World MVC
Real World MVC
 
Omnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the ThingsOmnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the Things
 
Building DSLs With Eclipse
Building DSLs With EclipseBuilding DSLs With Eclipse
Building DSLs With Eclipse
 
Android - Graphics Animation in Android
Android - Graphics Animation in AndroidAndroid - Graphics Animation in Android
Android - Graphics Animation in Android
 
jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
 
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
Core Image: The Most Fun API You're Not Using (CocoaConf Columbus 2014)
 

Destacado

Ops management lecture 5 quality management
Ops management lecture 5 quality managementOps management lecture 5 quality management
Ops management lecture 5 quality managementjillmitchell8778
 
Business Planning & Entrepreneurship
Business Planning & EntrepreneurshipBusiness Planning & Entrepreneurship
Business Planning & EntrepreneurshipAditya Sheth
 
Everything You Need to Know About Entrepreneurship and Business Planning But ...
Everything You Need to Know About Entrepreneurship and Business Planning But ...Everything You Need to Know About Entrepreneurship and Business Planning But ...
Everything You Need to Know About Entrepreneurship and Business Planning But ...Homer Nievera
 
strategic marketing management chapter 9 and 10
strategic marketing management chapter 9 and 10 strategic marketing management chapter 9 and 10
strategic marketing management chapter 9 and 10 Tehzeeb Tariq
 
STRATEGY EVALUATION
STRATEGY EVALUATIONSTRATEGY EVALUATION
STRATEGY EVALUATIONsylvme
 
Chapter 2 leadership
Chapter 2 leadershipChapter 2 leadership
Chapter 2 leadershipInazarina Ady
 
Mc Donalds Pakistan (Presence & Competition)
Mc Donalds Pakistan (Presence & Competition)Mc Donalds Pakistan (Presence & Competition)
Mc Donalds Pakistan (Presence & Competition)Mitsui & Co., Ltd.
 
Entrepreneurship and Business Planning Lecture Compilation
Entrepreneurship and Business Planning Lecture CompilationEntrepreneurship and Business Planning Lecture Compilation
Entrepreneurship and Business Planning Lecture CompilationAMS Malicse-Somoray
 
Strategic marketing management
Strategic marketing managementStrategic marketing management
Strategic marketing managementHailemariam Kebede
 
Strategic marketing ppt @ mba
Strategic marketing ppt @ mbaStrategic marketing ppt @ mba
Strategic marketing ppt @ mbaBabasab Patil
 
Marketing strategies
Marketing strategiesMarketing strategies
Marketing strategiesmarketpedia_k
 
Total quality management tools and techniques
Total quality management tools and techniquesTotal quality management tools and techniques
Total quality management tools and techniquesbhushan8233
 
How To Create Strategic Marketing Plan
How To Create Strategic Marketing PlanHow To Create Strategic Marketing Plan
How To Create Strategic Marketing PlanLalit Kale
 
Marketing strategy ppt slides
Marketing strategy ppt slidesMarketing strategy ppt slides
Marketing strategy ppt slidesYodhia Antariksa
 

Destacado (20)

Ops management lecture 5 quality management
Ops management lecture 5 quality managementOps management lecture 5 quality management
Ops management lecture 5 quality management
 
Business Planning & Entrepreneurship
Business Planning & EntrepreneurshipBusiness Planning & Entrepreneurship
Business Planning & Entrepreneurship
 
Everything You Need to Know About Entrepreneurship and Business Planning But ...
Everything You Need to Know About Entrepreneurship and Business Planning But ...Everything You Need to Know About Entrepreneurship and Business Planning But ...
Everything You Need to Know About Entrepreneurship and Business Planning But ...
 
Leadership and tqm
Leadership and tqmLeadership and tqm
Leadership and tqm
 
strategic marketing management chapter 9 and 10
strategic marketing management chapter 9 and 10 strategic marketing management chapter 9 and 10
strategic marketing management chapter 9 and 10
 
STRATEGY EVALUATION
STRATEGY EVALUATIONSTRATEGY EVALUATION
STRATEGY EVALUATION
 
Chapter 2 leadership
Chapter 2 leadershipChapter 2 leadership
Chapter 2 leadership
 
Leadership for quality
Leadership for qualityLeadership for quality
Leadership for quality
 
Mc Donalds Pakistan (Presence & Competition)
Mc Donalds Pakistan (Presence & Competition)Mc Donalds Pakistan (Presence & Competition)
Mc Donalds Pakistan (Presence & Competition)
 
Strategic marketing
Strategic marketingStrategic marketing
Strategic marketing
 
Entrepreneurship and Business Planning Lecture Compilation
Entrepreneurship and Business Planning Lecture CompilationEntrepreneurship and Business Planning Lecture Compilation
Entrepreneurship and Business Planning Lecture Compilation
 
Leadership & strategic Planning for Total Quality Management (TQM)
Leadership & strategic Planning for Total Quality Management (TQM)Leadership & strategic Planning for Total Quality Management (TQM)
Leadership & strategic Planning for Total Quality Management (TQM)
 
Strategic marketing management
Strategic marketing managementStrategic marketing management
Strategic marketing management
 
Strategic marketing ppt @ mba
Strategic marketing ppt @ mbaStrategic marketing ppt @ mba
Strategic marketing ppt @ mba
 
Marketing strategies
Marketing strategiesMarketing strategies
Marketing strategies
 
Total quality management tools and techniques
Total quality management tools and techniquesTotal quality management tools and techniques
Total quality management tools and techniques
 
How To Create Strategic Marketing Plan
How To Create Strategic Marketing PlanHow To Create Strategic Marketing Plan
How To Create Strategic Marketing Plan
 
Marketing plan ppt slides
Marketing plan ppt slidesMarketing plan ppt slides
Marketing plan ppt slides
 
Marketing strategy ppt slides
Marketing strategy ppt slidesMarketing strategy ppt slides
Marketing strategy ppt slides
 
Customer Service Strategy
Customer Service StrategyCustomer Service Strategy
Customer Service Strategy
 

Similar a Look Again at the ZCA

【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろうUnity Technologies Japan K.K.
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!Alessandro Giorgetti
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart JfokusLars Vogel
 
Gnizr Architecture (for developers)
Gnizr Architecture (for developers)Gnizr Architecture (for developers)
Gnizr Architecture (for developers)hchen1
 
Object Oriented Views / Aki Salmi
Object Oriented Views / Aki SalmiObject Oriented Views / Aki Salmi
Object Oriented Views / Aki SalmiAki Salmi
 
From Android NDK To AOSP
From Android NDK To AOSPFrom Android NDK To AOSP
From Android NDK To AOSPMin-Yih Hsu
 
NinjaScript and Mizugumo 2011-02-05
NinjaScript and Mizugumo 2011-02-05NinjaScript and Mizugumo 2011-02-05
NinjaScript and Mizugumo 2011-02-05lrdesign
 
Python_for_Visual_Effects_and_Animation_Pipelines
Python_for_Visual_Effects_and_Animation_PipelinesPython_for_Visual_Effects_and_Animation_Pipelines
Python_for_Visual_Effects_and_Animation_PipelinesRussell Darling
 
Build UI of the Future with React 360
Build UI of the Future with React 360Build UI of the Future with React 360
Build UI of the Future with React 360RapidValue
 
Android 101 - Introduction to Android Development
Android 101 - Introduction to Android DevelopmentAndroid 101 - Introduction to Android Development
Android 101 - Introduction to Android DevelopmentAndy Scherzinger
 
Dependency Injection and Autofac
Dependency Injection and AutofacDependency Injection and Autofac
Dependency Injection and Autofacmeghantaylor
 
D7 entities fields
D7 entities fieldsD7 entities fields
D7 entities fieldscyberswat
 
Getting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperGetting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperFabrit Global
 
The advantage of developing with TypeScript
The advantage of developing with TypeScript The advantage of developing with TypeScript
The advantage of developing with TypeScript Corley S.r.l.
 

Similar a Look Again at the ZCA (20)

【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!
 
Titanium Alloy Tutorial
Titanium Alloy TutorialTitanium Alloy Tutorial
Titanium Alloy Tutorial
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart Jfokus
 
Gnizr Architecture (for developers)
Gnizr Architecture (for developers)Gnizr Architecture (for developers)
Gnizr Architecture (for developers)
 
Object Oriented Views / Aki Salmi
Object Oriented Views / Aki SalmiObject Oriented Views / Aki Salmi
Object Oriented Views / Aki Salmi
 
From Android NDK To AOSP
From Android NDK To AOSPFrom Android NDK To AOSP
From Android NDK To AOSP
 
NinjaScript and Mizugumo 2011-02-05
NinjaScript and Mizugumo 2011-02-05NinjaScript and Mizugumo 2011-02-05
NinjaScript and Mizugumo 2011-02-05
 
Python_for_Visual_Effects_and_Animation_Pipelines
Python_for_Visual_Effects_and_Animation_PipelinesPython_for_Visual_Effects_and_Animation_Pipelines
Python_for_Visual_Effects_and_Animation_Pipelines
 
Build UI of the Future with React 360
Build UI of the Future with React 360Build UI of the Future with React 360
Build UI of the Future with React 360
 
Android 101 - Introduction to Android Development
Android 101 - Introduction to Android DevelopmentAndroid 101 - Introduction to Android Development
Android 101 - Introduction to Android Development
 
Dependency Injection and Autofac
Dependency Injection and AutofacDependency Injection and Autofac
Dependency Injection and Autofac
 
D7 entities fields
D7 entities fieldsD7 entities fields
D7 entities fields
 
Getting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperGetting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular Developer
 
The advantage of developing with TypeScript
The advantage of developing with TypeScript The advantage of developing with TypeScript
The advantage of developing with TypeScript
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
React nativebeginner1
React nativebeginner1React nativebeginner1
React nativebeginner1
 
Embedded d2w
Embedded d2wEmbedded d2w
Embedded d2w
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 

Último

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Último (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Look Again at the ZCA

  • 1. The ZCA Building elegant things
  • 2. Overview • A real world problem. • An explanation of the core ZCA concepts. • A simple model of the problem to use during the talk. • Code to apply concepts in the context of the simple model.
  • 3. The Problem Outline of the problem which led me to appreciate the ZCA
  • 4. The newsletter problem • Types designed for display on the web which we couldn't edit. • But which were in a good class hierarchy. • But we need to reformat some of them for display in a newsletter—and format the rest in a generic manner. • And, as always, we’re on a deadline. • The ZCA can help us with this problem
  • 5. A “standard” A Typical Day As Gregor Samsa awoke one morning from item just gets uneasy dreams he found himself transformed a title and in his bed into a monstrous vermin. More... description. Birthday News: “I feel no older” A news item After celebrating his 27th birthday, gets a picture a man claimed today to “feel no older” than the day before. More... beside it. Paris in the Autumn view the album And for a photo album, why not just some photos?
  • 6. Modelling the problem • I’m going to use the problem I just described as a basis. • We’re going to work through a simplified version to go over the primary concepts in the ZCA. • First, let’s look at the concepts.
  • 7. Core Concepts Fire up your diggers
  • 8. Let’s talk about Zope • Zope = Zope Object Publishing Environment. • Zope’s model is that of an object graph. • Both content and functionality are stored in Zope’s object database (the ZODB). • Zope 2 was a bit all or nothing: inventing wheels, very interwoven.
  • 9. I <3 Zope http://bit.ly/dtbNqj
  • 10. Zope 3 • Zope 3 was the reformulation of Zope into components. • The ZCA was built to meld these components together into a web platform. • It’s not crazy.
  • 11. The ZCA • A Service Locator—it helps the parts of your application find each other without tight coupling. • Components are registered with a central registry, which responds to queries. • Configuration decides what component provides a given function. • Though it would be possible to write a plugin architecture for your project, the ZCA is already there and well tested. We provide I need function X function X I can help
  • 12. Interfaces • Defines a set of functionality a thing promises to provide. • A gentleman’s agreement, not a contract. • Can be implemented any object, unlike some other languages. • The core of the ZCA: • You can ask for an object which implements an interface; • Or an object to convert from one interface to another.
  • 13. Interfaces ZODB LDAP User Code SQL DB isValidUser() addUser() removeUser() ISecurityProvider
  • 14. Utilities • A utility is an object which implements a specific interface. • You register the object with the ZCA, telling the ZCA the object is a utility which implements the interface. • Then ask for it later from anywhere in your program.
  • 15. Utilities ZODB LDAP User Code SQL DB isValidUser() addUser() removeUser() “implements” ISecurityProvider
  • 16. Adapters • Adapters can convert from one or more interface to another. • In Zope they are often used to add functionality in addition to just altering and interface.
  • 17. Adapters SQL DB Adapter User Code userIsOkay() userIsOkay() isValidUser() isValidUser() addUser() removeUser() ISecurityProvider
  • 18. Multi-Adaptors • Multi-adaptors adapt more than one input interface to a single output interface. • Zope uses this for rendering pages by adapting as follows: HTTP Request View Adapter (rendered page) Content Item
  • 19. Is this too far? • Zope 3 uses multi-adaptors to register event handlers: Like the snappily named Event type is IObjectModifiedEvent defined by Interface Callable which Adapter handles event Content Item
  • 20. Work ed Exam ple
  • 21. The simplified model Finder Selects items for sending Content to select from. IItemFinder Renderer for most items Rendering “Pipeline” Renderer for news items Renderer for photo albums INewsletterItemRenderer
  • 22. Content Objects StandardItem SubStandardItem PhotoAlbum NewsItem
  • 23. The content objects # Note they have no knowledge of the # ZCA. class StandardItem(object): class NewsItem(StandardItem): def __init__(self, title): def __init__(self, title, self.title = title description, date): self.title = title @property self.description = description def url(self): self.date = date """Generate a url""" [...] class SubStandardItem(StandardItem): class PhotoAlbum(StandardItem): """This item should be renderable by the adaptor for StandardItem""" def __init__(self, title, thumbnails): def __init__(self, title): self.title = title self.title = "SUB! %s" % title self.thumbnails = thumbnails
  • 24. A utility to find them class IItemFinder(Interface): def __call__(): """Return a list of items which descend from StandardItem.""" class ItemFinder(object): implements(IItemFinder) def __call__(self): The ZCA bits """Hardcode for demo purposes""" return [ PhotoAlbum("Crocodiles", []), StandardItem("A Standard Item"), SubStandardItem("A second standard item"), NewsItem("Man Feels No Different on Birthday", """ Man reports feeling no different on 27th birthday from the day before.""", "10th July, 2010"), NewsItem("Less Newsworthy", """ The world is going to end tomorrow at 14.27.""", "13th June, 2010"), [... some more items ...] ]
  • 25. Adaptors to render them class INewsletterItemRenderer(Interface): def render(): Our interface """Render an item""" class BaseRenderer(): """Base class to do what all the renderers need to do"""All renderers implements(INewsletterItemRenderer) def __init__(self, context): implement self.context = context class BaseContentToNewsletterBlockRenderer(BaseRenderer): the interface adapts(StandardItem) def render(self): and adapt a return "*** %s (Standard Item)n %s" % ( self.context.title, self.context.url) content item class NewsItemToNewsletterBlockRenderer(BaseRenderer): to it adapts(NewsItem) def render(self): return "*** %s (News)n %sn %snn %s" % ( self.context.title, self.context.date, self.context.url, [...format the body...] class PhotoAlbumToNewsletterBlockRenderer(BaseRenderer): [...]
  • 26. Register them # These all use the Global registry. It's possible to # have separate registries if needed for your application. from zope.component import provideAdapter, provideUtility, getUtility # (1) A utility needs to be instantiated before registering. provideUtility(ItemFinder(), IItemFinder) # (2) Adaptors will be created as needed so don’t need # creating. provideAdapter(BaseContentToNewsletterBlockRenderer, (StandardItem,), INewsletterItemRenderer) provideAdapter(NewsItemToNewsletterBlockRenderer, (NewsItem,), INewsletterItemRenderer) provideAdapter(PhotoAlbumToNewsletterBlockRenderer, (PhotoAlbum,), INewsletterItemRenderer)
  • 27. And use them Get the utility and call it to get item list: finder = getUtility(IItemFinder) items = finder() The ZCA will find the right renderer: body = "nn".join([ INewsletterBlockRenderer(x).render() for x in finder ]) Let’s go! print """ Dear subscriber, %s We hope you enjoyed this update, The Team. """ % body
  • 28. Summary • ZCA allows for building robustly componentised applications. • Core is: Interfaces, Utilities and Adapters. • It’s well tested and small enough to easily learn. • It’s powerful enough for production use--and widely deployed. • Suggested further reading: http://www.muthukadan.net/docs/zca.html
  • 29. Get in contact: mike@netsight.co.uk Thank you for watching! Or catch me in the hallways!