From 537b7caf246ef52c0bb383705231f005d3defffe Mon Sep 17 00:00:00 2001 From: waldo1001 Date: Thu, 10 Feb 2022 16:06:55 +0100 Subject: [PATCH 1/6] Event Bridge Patten --- .../BCPatterns/event-bridge-pattern/index.md | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 content/BCPatterns/event-bridge-pattern/index.md diff --git a/content/BCPatterns/event-bridge-pattern/index.md b/content/BCPatterns/event-bridge-pattern/index.md new file mode 100644 index 00000000..3a9beac1 --- /dev/null +++ b/content/BCPatterns/event-bridge-pattern/index.md @@ -0,0 +1,116 @@ ++++ +title = "Event Bridge Pattern" +weight = 1180 ++++ +This is a guideline, some parts are optional (if there's no content, remove the whole paragraph). + +<_Created by (company), Described by (company)_\> + +## Abstract + +In the world of interfaces, it is important to preserve (certain) events over multiple implementation of the interface. + +## Context + +An app can have interfaces. +It makes it possible for other apps to extend/change the implementations of a certain part of the business logic. + +Like in this example, we have an interface, to implement different ways for getting weights from scales: + +```AL +interface "IScale" +{ + procedure GetWeight(): Decimal; + procedure Tare(); +} +``` + +## Problem + +Multiple apps can subscribe to certain events of the app. +When a new implementation is created, we need to make sure that these events are raised at the right times. If those events were published on the implementation codeunit, it might very well be that those events will not be raised, hard to find, or whatever. + +So, if we would implement it like this, it isn't really extensible, as a different implemention would impement different events .. and it's not possible to subscribe to all of them (inculding future implementations) + +```AL +codeunit 50407 "Scale Wrong" implements IScale +{ + + procedure GetWeight() Result: Decimal; + begin + //TODO: Implement Bar GetWeight + OnAfterGetWeight(Result); + end; + + procedure Tare(); + begin + //TODO: Implement Bar Tare + OnAfterTare(); + end; + + [IntegrationEvent(false, false)] + procedure OnAfterGetWeight(var Result: Decimal) + begin + end; + + [IntegrationEvent(false, false)] + procedure OnAfterTare() + begin + end; +} +``` + +## Description + +To mitigate this problem, we can work with a new, dedicated, isolated, codeunit, with publish events to be able to raise them from different places. + +``` +codeunit 50406 "IScale Triggers" +{ + [IntegrationEvent(false, false)] + procedure OnAfterGetWeight(var Result: Decimal) + begin + end; + + [IntegrationEvent(false, false)] + procedure OnAfterTare() + begin + end; +} +``` + +This way, it's possible to raise the events in all the implementations: + +```AL +codeunit 50405 "Scale Bar" implements IScale +{ + var + IScaleTriggers: Codeunit "IScale Triggers"; + + procedure GetWeight() Result: Decimal; + begin + //TODO: Implement Bar GetWeight + IScaleTriggers.OnAfterGetWeight(Result); + end; + + procedure Tare(); + begin + //TODO: Implement Bar Tare + IScaleTriggers.OnAfterTare(); + end; +} +``` + +## Benefits + +This new codeunit, with public events, makes the events accessible from all places, including new apps that are dependent from this app, and wants to extend the + +The naming convention (both starting with "IScale") also makes it very easy to find that corresponding events for the interface. + +## When not to use + +Obiously, the events should be carefully considered: only the events that make sense to "share" over all implementations, need this approach. + +## Discussions + +Create a discussions-page of your pattern, and add the sentence "You can discuss this pattern [here](https://github.com/microsoft/alguidelines/discussions/66)" with the right link to that discussions-page. \ No newline at end of file From 19020978ad7978da01ff7a4b2ae972d916f59be2 Mon Sep 17 00:00:00 2001 From: waldo1001 Date: Thu, 10 Feb 2022 16:20:19 +0100 Subject: [PATCH 2/6] authors --- content/BCPatterns/event-bridge-pattern/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/BCPatterns/event-bridge-pattern/index.md b/content/BCPatterns/event-bridge-pattern/index.md index 3a9beac1..ba1fb9b6 100644 --- a/content/BCPatterns/event-bridge-pattern/index.md +++ b/content/BCPatterns/event-bridge-pattern/index.md @@ -4,7 +4,7 @@ weight = 1180 +++ This is a guideline, some parts are optional (if there's no content, remove the whole paragraph). -<_Created by (company), Described by (company)_\> +<_Created by waldo & Arend-Jan Kauffmann, Described by waldo_\> ## Abstract From 1d005b332d59c5ff520e27d748860ccf121c16ab Mon Sep 17 00:00:00 2001 From: waldo1001 Date: Thu, 10 Feb 2022 16:24:39 +0100 Subject: [PATCH 3/6] cleanup --- content/BCPatterns/event-bridge-pattern/index.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/BCPatterns/event-bridge-pattern/index.md b/content/BCPatterns/event-bridge-pattern/index.md index ba1fb9b6..0d210e4b 100644 --- a/content/BCPatterns/event-bridge-pattern/index.md +++ b/content/BCPatterns/event-bridge-pattern/index.md @@ -2,7 +2,6 @@ title = "Event Bridge Pattern" weight = 1180 +++ -This is a guideline, some parts are optional (if there's no content, remove the whole paragraph). <_Created by waldo & Arend-Jan Kauffmann, Described by waldo_\> From 15c06bd0b27033228f58ae4691e68077668c49e0 Mon Sep 17 00:00:00 2001 From: waldo1001 Date: Thu, 10 Feb 2022 17:01:08 +0100 Subject: [PATCH 4/6] cleanup --- content/BCPatterns/event-bridge-pattern/index.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/content/BCPatterns/event-bridge-pattern/index.md b/content/BCPatterns/event-bridge-pattern/index.md index 0d210e4b..69ccb946 100644 --- a/content/BCPatterns/event-bridge-pattern/index.md +++ b/content/BCPatterns/event-bridge-pattern/index.md @@ -29,12 +29,11 @@ interface "IScale" Multiple apps can subscribe to certain events of the app. When a new implementation is created, we need to make sure that these events are raised at the right times. If those events were published on the implementation codeunit, it might very well be that those events will not be raised, hard to find, or whatever. -So, if we would implement it like this, it isn't really extensible, as a different implemention would impement different events .. and it's not possible to subscribe to all of them (inculding future implementations) +So, if we would implement it like this, it isn't really extensible, as a different implemention would implement different events .. and it's not possible to subscribe to all of them (including future implementations) ```AL codeunit 50407 "Scale Wrong" implements IScale { - procedure GetWeight() Result: Decimal; begin //TODO: Implement Bar GetWeight @@ -63,7 +62,7 @@ codeunit 50407 "Scale Wrong" implements IScale To mitigate this problem, we can work with a new, dedicated, isolated, codeunit, with publish events to be able to raise them from different places. -``` +```AL codeunit 50406 "IScale Triggers" { [IntegrationEvent(false, false)] @@ -108,7 +107,7 @@ The naming convention (both starting with "IScale") also makes it very easy to f ## When not to use -Obiously, the events should be carefully considered: only the events that make sense to "share" over all implementations, need this approach. +Obviously, the events should be carefully considered: only the events that make sense to "share" over all implementations, need this approach. ## Discussions From 49e20f6e7278fa8753a0acf97e55b92f4faffe09 Mon Sep 17 00:00:00 2001 From: waldo Date: Thu, 10 Feb 2022 23:30:21 +0100 Subject: [PATCH 5/6] Update content/BCPatterns/event-bridge-pattern/index.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Christian Bräunlich --- content/BCPatterns/event-bridge-pattern/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/BCPatterns/event-bridge-pattern/index.md b/content/BCPatterns/event-bridge-pattern/index.md index 69ccb946..9fbceb5e 100644 --- a/content/BCPatterns/event-bridge-pattern/index.md +++ b/content/BCPatterns/event-bridge-pattern/index.md @@ -60,7 +60,7 @@ codeunit 50407 "Scale Wrong" implements IScale ## Description -To mitigate this problem, we can work with a new, dedicated, isolated, codeunit, with publish events to be able to raise them from different places. +To mitigate this problem, we can work with a new, dedicated and isolated codeunit, with publisher events to be able to raise them from different places. ```AL codeunit 50406 "IScale Triggers" From 812ec064415e35c47a85fb042981cee88b6490c6 Mon Sep 17 00:00:00 2001 From: waldo1001 Date: Thu, 10 Feb 2022 23:50:22 +0100 Subject: [PATCH 6/6] changed discussions --- content/BCPatterns/event-bridge-pattern/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/BCPatterns/event-bridge-pattern/index.md b/content/BCPatterns/event-bridge-pattern/index.md index 69ccb946..6f9ce063 100644 --- a/content/BCPatterns/event-bridge-pattern/index.md +++ b/content/BCPatterns/event-bridge-pattern/index.md @@ -111,4 +111,4 @@ Obviously, the events should be carefully considered: only the events that make ## Discussions -Create a discussions-page of your pattern, and add the sentence "You can discuss this pattern [here](https://github.com/microsoft/alguidelines/discussions/66)" with the right link to that discussions-page. \ No newline at end of file +You can discuss this pattern [here](https://github.com/microsoft/alguidelines/discussions/66) \ No newline at end of file