SlideShare ist ein Scribd-Unternehmen logo
1 von 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!

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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)
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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.
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...itnewsafrica
 

Kürzlich hochgeladen (20)

Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
 

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!