bcquality/microsoft/knowledge/interfaces/prefer-interface-over-case-branching.good.al
Jesper Schulz-Wedde 23d5478ac6
Add interfaces knowledge domain and review leaf skill (#42)
Adds the interfaces knowledge domain covering AL interfaces and enum-with-implementation: three atomic articles with good/bad AL samples, a new al-interfaces-review leaf skill, and additive wiring into al-code-review and the README. Purely additive; no contract change.

Part of #34.

Co-authored-by: Jesper Schulz-Wedde <jesper.schulzwedde@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-25 12:20:56 +02:00

47 lines
1.1 KiB
AL

interface IShippingRate
{
procedure CalculateRate(Weight: Decimal): Decimal;
}
codeunit 50200 "Standard Shipping Rate" implements IShippingRate
{
procedure CalculateRate(Weight: Decimal): Decimal
begin
exit(Weight * 1.5);
end;
}
codeunit 50201 "Express Shipping Rate" implements IShippingRate
{
procedure CalculateRate(Weight: Decimal): Decimal
begin
exit((Weight * 1.5) + 25);
end;
}
enum 50202 "Shipping Method" implements IShippingRate
{
Extensible = true;
value(0; Standard)
{
Implementation = IShippingRate = "Standard Shipping Rate";
}
value(1; Express)
{
Implementation = IShippingRate = "Express Shipping Rate";
}
}
codeunit 50203 "Shipping Charge"
{
// Dispatch is automatic: assign the enum to the interface variable and call.
// A new method = one new enum value + one impl codeunit, with no edit here.
procedure GetRate(Method: Enum "Shipping Method"; Weight: Decimal): Decimal
var
RateProvider: Interface IShippingRate;
begin
RateProvider := Method;
exit(RateProvider.CalculateRate(Weight));
end;
}