{"id":152,"date":"2022-05-24T14:01:41","date_gmt":"2022-05-24T21:01:41","guid":{"rendered":"http:\/\/www.barrybriggs.com\/blog\/?p=152"},"modified":"2022-05-24T14:04:45","modified_gmt":"2022-05-24T21:04:45","slug":"composability-and-events","status":"publish","type":"post","link":"http:\/\/www.barrybriggs.com\/blog\/uncategorized\/composability-and-events\/","title":{"rendered":"Composability and Events"},"content":{"rendered":"\n<p>Apparently one of the new buzzwords is <a href=\"https:\/\/www.gartner.com\/smarterwithgartner\/gartner-keynote-the-future-of-business-is-composable\">composability<\/a>, meaning everything from reorganizing (\u201cpivoting\u201d) your business quickly in response to changing market conditions to adding new technical capabilities to your applications as needed. As new features come online, the story goes, you should be able to seamlessly (that word!) add them to your applications as you need them, and ditch the ones you don\u2019t need any more. <\/p>\n\n\n\n<p>Now, let\u2019s see, where O where have I heard this story\nbefore? DLLs, Java Applets, ActiveX, Enterprise JavaBeans, Service-Oriented\nArchitecture, Service Provider Interfaces, the API Economy: it seems like every\nfew years we have to rediscover how utterly cool modularity and (if we\u2019re\nreally chic) loose coupling are.<\/p>\n\n\n\n<p>Technically, composability appears to mean something like a combination of SPIs and APIs. Microsoft touts the fact that it\u2019s easy to add a FedEx module to <a href=\"https:\/\/cloudblogs.microsoft.com\/dynamics365\/bdm\/2022\/04\/14\/dynamics-365-breathes-composability-into-enterprise-resource-planning-modernization\/\">Dynamics <\/a>to enable shipping when it absolutely, positively has to be there overnight. <\/p>\n\n\n\n<p>Cool.<\/p>\n\n\n\n<p>Real composability, it seems to me, means a near-infinitely malleable\nproduct whose behavior can be adapted to any reasonable need. <\/p>\n\n\n\n<p>How do you do <em>that? <\/em>(What does that even mean?) <\/p>\n\n\n\n<p>Of course part of the answer involves a good, solid set of APIs to an application, documented, hopefully, with <a href=\"https:\/\/www.openapis.org\/\">OpenAPI<\/a> (nee Swagger) or something similar. Enough has been written about Why APIs Are Good that I\u2019m not going to repeat their virtues.<\/p>\n\n\n\n<p>But what about when you want to <em>change, <\/em>or <em>augment,\n<\/em>or even <em>replace <\/em>the core processing of an application feature? Well,\nof course many applications support events so you can know when they\u2019re about to\ndo something, or when they\u2019ve done something. <\/p>\n\n\n\n<p>But back in the day doing Lotus 1-2-3 my team and I decided\nwe needed something more powerful. Our scripting language team (LotusScript) was\ndemanding deep access to the product internals, and our addons like our Solver,\neven deeper ones. They needed to execute code in some cases before the relevant\napplication code, in some cases after, for example, sideloading a file needed\nby the addon. And in certain cases \u2013 for example, loading a file type not\nsupported by the original app \u2013 they needed to replace the existing code. <\/p>\n\n\n\n<p>We had a pretty comprehensive set of APIs. But they didn\u2019t\nsolve the problem. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Problem<\/h2>\n\n\n\n<p>Here\u2019s the core idea: imagine a file load routine (this is pseudocode, so don\u2019t get upset): <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"683\" height=\"284\" src=\"http:\/\/www.barrybriggs.com\/blog\/wp-content\/uploads\/2022\/05\/em1.png\" alt=\"\" class=\"wp-image-153\" srcset=\"http:\/\/www.barrybriggs.com\/blog\/wp-content\/uploads\/2022\/05\/em1.png 683w, http:\/\/www.barrybriggs.com\/blog\/wp-content\/uploads\/2022\/05\/em1-300x125.png 300w\" sizes=\"auto, (max-width: 683px) 100vw, 683px\" \/><\/figure>\n\n\n\n<p>Pretty straightforward: parse the file extension and pass it\noff the right handler. No worries. <\/p>\n\n\n\n<p>But what if you want to load a PDF? Or a text file? Or an\nMP3, for whatever reason? (Hey why not?) <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introducing the Event Manager<\/h2>\n\n\n\n<p>The idea of our <strong>Event Manager<\/strong> was simple: an addon could register for an event that happened <em>before <\/em>the core code ran, and\/or an event that ran <em>after <\/em>the core code. In addition, the addon could return one of three values:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Ran successfully<\/li><li>Ran\nsuccessfully, and bypass core code<\/li><li>Error<\/li><\/ul>\n\n\n\n<p>In other words, something like this: <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"988\" height=\"490\" src=\"http:\/\/www.barrybriggs.com\/blog\/wp-content\/uploads\/2022\/05\/em2.png\" alt=\"\" class=\"wp-image-154\" srcset=\"http:\/\/www.barrybriggs.com\/blog\/wp-content\/uploads\/2022\/05\/em2.png 988w, http:\/\/www.barrybriggs.com\/blog\/wp-content\/uploads\/2022\/05\/em2-300x149.png 300w, http:\/\/www.barrybriggs.com\/blog\/wp-content\/uploads\/2022\/05\/em2-768x381.png 768w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/figure>\n\n\n\n<p>Here you can see the first thing that happens is any addons that have registered for the \u201cOpenFile\u201d Before-Event get notified, and can either ignore, augment \u2013 or replace \u2013 the core handling, and thus can load a wholly new file type, if desired. (EventManager.BeforeEvent() fans out the event to all registered addons.)<\/p>\n\n\n\n<p>The After-Event has\nless options, for obvious reasons. It can be used for logging, or can be used\nto (say) load a shadow file (as many of the 1-2-3 addons did). In this case the\naddon has to handle any errors that occur as the core code may not understand\nthe addons\u2019 semantics. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Value<\/h2>\n\n\n\n<p>We found this pattern very useful in 1-2-3, so much so that\nI ported the concept to Lotus Notes some time after. In some ways, I think,\nthis provides a good benchmark of what composability should really be. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apparently one of the new buzzwords is composability, meaning everything from reorganizing (\u201cpivoting\u201d) your business quickly in response to changing market conditions to adding new technical capabilities to your applications as needed. As new features come online, the story goes, you should be able to seamlessly (that word!) add them to your applications as you &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.barrybriggs.com\/blog\/uncategorized\/composability-and-events\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Composability and Events&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"episode_type":"","audio_file":"","cover_image":"","cover_image_id":"","duration":"","filesize":"","date_recorded":"","explicit":"","block":"","filesize_raw":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.barrybriggs.com\/blog\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.barrybriggs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.barrybriggs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.barrybriggs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.barrybriggs.com\/blog\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":2,"href":"http:\/\/www.barrybriggs.com\/blog\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":156,"href":"http:\/\/www.barrybriggs.com\/blog\/wp-json\/wp\/v2\/posts\/152\/revisions\/156"}],"wp:attachment":[{"href":"http:\/\/www.barrybriggs.com\/blog\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.barrybriggs.com\/blog\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.barrybriggs.com\/blog\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}