Attachment 'componentizing-to-heaven.html'


Componentizing a Stairway to Heaven

Why Componentize

Imagine yourself writing a "generic notifier". You have a "notifier object" with the notification configuration. Various specific notifiers would like to keep persistent information (the IRC notifier likes to keep the IRC connection, the mailer notifier keeps track of "unsent notifications" so it can aggregate notifications close in time in one mail, etc.) One way to do it, of course, is to keep .mailer, .ircer, etc. attributes on the notifier. Then you need to co-ordinate, and have built a dependency from the generic infrastructure to the specific implementations. That is bad?

So, of course, you can let the mail infrastructure add the .mailer attribute. In a sense, that shifts the co-ordination problem from a centralized one to a decentralized one, with no means to co-ordinate. The "hope and prayer" strategy (each person has to make sure their attributes don't step on their neighbour's) has the problems that a) it usually works and b) when it breaks, it breaks in the most inscrutable ways.

How Components

Guidelines for doing that:

    def mail(self, o):
        p = IMailer(o)
        if p is None:
            # This is where we decide our mail strategy:
            p = DelayedMailer(o)
            o.addComponent(p, ignoreClass=True)

This scales up a way to hang ad-hoc properties on o (so that, for example, if the same o is passed, the same value is used.

Wait a minute, what about the stairway to heaven? Oh, right, then.

class IGlitter(Interface):

class Gold(object):

So, you see, all that glitters is gold.

So is that the best part?


The really neat thing is that now modules who want to co-operate can do that easily. Ideally, it means reaching true "component nirvana".

But MosheZ! What is "component nirvana" please?

Am I glad you asked! Component Nirvana is the ideal of "zero infratructure": whether something is "infrastructure" or "application" is not encoded in the Python, but is only a human attribute: the mailer can use the IRC if it wants the dependency, or we can write an ISetttings interface all the modules use: or all the modules that are interested in those settings, in any case.

This is the so-called "Raviolli" pattern (or, done badly, the "Risotto" pattern) as opposed to the classic "Lasagna" pattern (layered infrastructure, from generic to specific) or "Spaghetti" pattern (every object accesses every object it feels like, with no internal division).

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-08-07 18:00:31, 157.0 KB) [[attachment:_FasterThenAssemblerLightning.odp]]
  • [get | view] (2006-07-05 14:22:06, 197.5 KB) [[attachment:bad-presentation.pdf]]
  • [get | view] (2006-07-05 12:55:26, 2.9 KB) [[attachment:componentizing-to-heaven.html]]
  • [get | view] (2006-07-10 11:51:27, 47.2 KB) [[attachment:crowd-security-policy.pdf]]
  • [get | view] (2006-07-13 20:22:42, 175.4 KB) [[attachment:fixing-dbc.pdf]]
  • [get | view] (2006-07-06 16:23:24, 362.7 KB) [[attachment:missing-word-security.pdf]]
  • [get | view] (2006-07-06 20:50:28, 220.2 KB) [[attachment:py_atlas_networks.pdf]]
  • [get | view] (2006-07-05 13:04:39, 34.2 KB) [[attachment:pydoctor.pdf]]
  • [get | view] (2006-07-05 16:36:33, 2028.6 KB) [[attachment:teachingPythonECP.pdf]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

Unable to edit the page? See the FrontPage for instructions.