Skip to main content

🧾 Understanding Interfaces in Business Central (With Real-Life Example)

💡 A Simple Guide for Beginners

If you're learning Microsoft Dynamics 365 Business Central, one concept that often feels confusing at first is Interfaces.

But don’t worry — let’s break it down in simple, real-world language so you can understand not just what interfaces are, but why they matter.


🧠 The Problem We Face in Real Projects

Imagine you’re building a payment system in Business Central.

Your company accepts:

  • 💳 Credit Card
  • 📱 UPI
  • 🏦 Bank Transfer

At first, a simple approach looks like this:

if PaymentType = 'Card' then
    ProcessCard()
else if PaymentType = 'UPI' then
    ProcessUPI()
else if PaymentType = 'Bank' then

    ProcessBank();

✅ Works fine… for now.

🚨 But Here’s What Happens Later

As your system grows:

  • New payment types get added (PayPal, Wallet, etc.)
  • Code becomes longer and harder to read
  • Every change requires modifying existing logic
  • Risk of breaking existing functionality increases

👉 This is where interfaces come to the rescue


🎯 What is an Interface? (In Simple Words)

Think of an interface like a rulebook.

It says: Anyone who wants to act as a payment method must follow these rules.

For example:

interface IPaymentMethod

{
    procedure ProcessPayment(Amount: Decimal);

}

👉 It just defines the rule — not the implementation.

🧩 Real-Life Design (How Professionals Build It)

Instead of one messy codeunit, we design the system in parts:


✅ 1. Interface (The Rulebook)

interface IPaymentMethod
{
    procedure ProcessPayment(Amount: Decimal);
}

✅ 2. Implementations (Specialists)

💳 Card Payment
codeunit CardPayment implements IPaymentMethod
{
    procedure ProcessPayment(Amount: Decimal)
    begin
        Message('Processing Card Payment of %1', Amount);
    end;
}

📱 UPI Payment
codeunit UPIPayment implements IPaymentMethod
{
    procedure ProcessPayment(Amount: Decimal)
    begin
        Message('Processing UPI Payment of %1', Amount);
    end;
}

✅ 3. Enum (The Smart Selector)

This is where Business Central becomes powerful:
enum PaymentMethod implements IPaymentMethod
{
    value(0; Card)
    {
        Implementation = IPaymentMethod = CardPayment;
    }

    value(1; UPI)
    {
        Implementation = IPaymentMethod = UPIPayment;
    }
}

👉 Now the system automatically knows:

  • Card → CardPayment
  • UPI → UPIPayment

✅ No need for IF conditions!


✅ 4. Shared Logic (Common Code)

Now comes a common doubt:

👉 What if some logic is same for all payment methods?

Answer: Put it in one place!

codeunit PaymentHelper
{
    procedure ValidateAmount(Amount: Decimal)
    begin
        if Amount <= 0 then
            Error('Invalid amount');
    end;


    procedure LogPayment(Amount: Decimal)
    begin
        Message('Logging payment of %1', Amount);
    end;

}

✅ 5. Main Processor (The Brain)
codeunit PaymentProcessor
{
    procedure Process(Rec: Record PaymentTable)
    var
        Helper: Codeunit PaymentHelper;
        Payment: Enum PaymentMethod;
        PaymentMethod: interface IPaymentMethod;
    begin
        // Common logic
        Helper.ValidateAmount(Rec.Amount);
        Helper.LogPayment(Rec.Amount);

        // Get selected method
        Payment := Rec.PaymentMethod;

        // Call correct implementation
        PaymentMethod.ProcessPayment(Rec.Amount);
    end;
}

🔥 What Just Happened?

✅ User selects payment type
✅ System stores it
✅ Main code runs common logic once
✅ Interface calls correct implementation automatically

👉 No IF conditions
👉 No messy code
👉 No duplication


🧠 Why This Design is Powerful

✅ 1. Easy to Extend

Add a new method like PayPal:

codeunit PayPalPayment implements IPaymentMethod


✅ 2. Clean & Readable

Main logic becomes:

Payment.ProcessPayment();

👉 Simple, clean, understandable

✅ 3. No Risk to Existing Logic

You don’t touch old code when adding new features.


✅ 4. Real Business Central Standard

Microsoft itself uses this pattern in:

  • Payment systems
  • Posting logic
  • Integrations
  • E-Documents

⚖️ But Is This Overkill?

👉 Not always.

✅ Use this approach when:

  • System will grow
  • Multiple variations exist
  • Other developers may extend it

❌ Avoid when:

  • Very small logic
  • One-time use
  • No future changes expected

🧠 Final Understanding


✅ One-Line Summary

👉 Interfaces help you move from messy IF conditions to clean, scalable, and future-proof design in Business Central.


🚀 Final Thought

At first, interfaces feel like: Extra work

But in real projects, they: ✅ Save time
✅ Reduce bugs
✅ Make your solution extensible

👉 That’s why professional BC developers rely on them.


Here’s a visual diagram of the architecture we discussed 👇

payment_architecture_diagram.png



🧠 How to Read This Diagram (Very Important)

🔽 Step-by-step flow:

  1. User Input

    • User selects payment method (Card / UPI)
  2. Table (Database)

    • Selection is stored in a field (Payment Method enum)
  3. Payment Processor (Main Codeunit)

    • Runs all common logic
      • ✅ Validation
      • ✅ Logging
  4. Interface (IPaymentMethod)

    • Defines what needs to be done
    • (e.g., ProcessPayment())
  5. Enum (Selector)

    • Decides which implementation to use
    • Maps:
      • Card → Card Payment codeunit
      • UPI → UPI Payment codeunit
  6. Implementation Codeunits

    • Actual logic runs:
      • 💳 Card handler
      • 📱 UPI handler

🎯 Key Insight from the Diagram

👉 Top part = common flow (shared logic)
👉 Bottom part = varying behavior (interface implementations)


💡 Why This Architecture Matters

  • ✅ No IF conditions in core logic
  • ✅ Clean separation of concerns
  • ✅ Easy to extend (add new payment types)
  • ✅ No duplicate code
  • ✅ Matches Microsoft’s real BC design

🧠 One-Line Understanding

👉 “Data decides, processor controls, interface delegates, codeunits execute.”

Comments

Popular posts from this blog

Improved performance features of Business Central 17

  In the training I’ve done to some partners last week, when talking about performances I shared an example of an extension with 3 features that I think are not so well known but that have a significant impact on how your code performs, expecially on a SaaS environment. That extension used the following features: Partial record loading Temporary Tables QueryCategory The  Partial record  capability  is a new feature available starting from Dynamics 365 Business Central 2020 Wave 2 (v17) and I think it’s one of my top personal desiderata from years. This feature permits you to load only the needed fields of a recordset (when accessing a data source) instead of loading the entire set of fields. This is particularly useful on reports and OData pages because you can avoid to do a SELECT * (plus JOINS with all the extension’s tables) and instead doing a SELECT of only the fields you need. Now you can do something like: procedure TestPartialRecord(): Decimal ...

Custom sheet name in RDLC Reports

Hi Readers, In this article we are going to discuss how to change the excel sheet name while using base Navision SAVEASEXCEL functionality. Applicable for RDLC reports of Navision and SSRS reports. Let’s say we have the following report that shows total sales by product category by territory:   When we export this report to Excel, we’d like each territory to appear in its own worksheet and each worksheet named after its territory: How do we make this work? Easy! 1) Put every group on its own page. 2) name each page using the same field the group uses. Step 1: Put each group on its own page To put each group on its own page, open the group’s property window. Then, in the Page Breaks category, put a check mark in the Between each instance of a group check box. Click OK to complete this step. Step 2: Name the pages of the group With the group selected in the Row Group s panel, press F4 to open the Properties window. Next, expand the Group ...

UPGRADE CUSTOMIZATIONS TO V2 EXTENSION (Application and Data)

From Navision 2018 Onwards, Navision only support v2 Extension. Dynamic Navision Extension will make upgrade easier. If customizations are converted into V2 extension that means v2 Extension consist upgraded Data as well as customizations, also it will be easy to upgrade into new version of Navision and apply CU updates. Below are the detailed steps to upgrade customizations into Navision 2018 v2 Extensions .  1) you have Customized database in Microsoft Dynamics Navision 2018. 2) Create the new table for each table that is customized or also for customized field in standard table but while creating table for standard table, add the primary key and customized field with same ID and Name in new table. For E.g.: I have created 1 table “Person” and 2 Customized Field (Test, Doc No) in “Sales Header”. Now create 2 New tables in 2018.  · Upg Sales Header -> Two base field (PK) and customized field -> Same ID and add primary key. Refer be...