Kotlin Multiplatform and the Shared Logic Model

From PiRho Knowledgebase
Jump to navigationJump to search

Summary: Kotlin Multiplatform (KMP) represents a distinct approach to cross-platform software development. Rather than attempting to share an application's entire user experience across platforms, KMP focuses on sharing the underlying business logic whilst preserving native user interfaces. This architectural model seeks to reduce duplication where it delivers the greatest value while respecting the unique characteristics of each platform. Understanding this philosophy is key to understanding why Kotlin Multiplatform differs from many other cross-platform technologies.

Context

As mobile applications became more sophisticated, organisations increasingly encountered a common problem.

Applications often contained large amounts of duplicate code.

For example:

Android Application

    User Interface
    Business Logic
    Networking
    Data Models
    Storage

iOS Application

    User Interface
    Business Logic
    Networking
    Data Models
    Storage

Although these applications were built for different platforms, much of their behaviour was identical.

This duplication increased:

  • Development effort
  • Testing effort
  • Maintenance effort
  • Risk of inconsistency

Cross-platform frameworks emerged to address this challenge.

However, not all frameworks attempted to solve the problem in the same way.

The Problem with Full Duplication

Traditional native development provides excellent platform integration and user experience.

However, it frequently requires the same functionality to be implemented multiple times.

Consider a banking application.

Both platforms may require:

  • Authentication
  • Security controls
  • Transaction processing
  • API communication
  • Validation rules
  • Data models

The behaviour should remain identical regardless of device.

Maintaining separate implementations creates opportunities for:

  • Bugs
  • Inconsistencies
  • Delayed feature delivery
  • Increased costs

Architects therefore began asking:

"Which parts of these applications are genuinely different?"

The Problem with Full Sharing

Some cross-platform frameworks attempt to maximise code reuse by sharing:

  • User interfaces
  • Business logic
  • Data access
  • Application workflows

This approach can be highly effective.

However, organisations sometimes discover that complete standardisation is not always desirable.

Users often expect native experiences.

Android users expect Android behaviour.

Apple users expect Apple behaviour.

The challenge therefore becomes balancing:

  • Consistency
  • Efficiency
  • Platform familiarity

This is the problem Kotlin Multiplatform was designed to address.

The Shared Logic Philosophy

Kotlin Multiplatform is based upon a simple observation:

Not every part of an application changes at the same rate.

Business rules often remain relatively stable.

User interfaces often evolve continuously.

Rather than sharing everything, Kotlin Multiplatform focuses on sharing the layers which provide the greatest long-term value.

The philosophy can be summarised as:

Share What Matters

Keep What Is Unique

Rather than attempting to eliminate platform differences, Kotlin Multiplatform embraces them.

What Is Shared?

Kotlin Multiplatform is typically used to share:

  • Business rules
  • Data models
  • API communication
  • Networking
  • Validation logic
  • Authentication processes
  • Encryption logic
  • Application services

These components frequently represent an application's core behaviour.

They define how the system works rather than how it appears.

What Remains Native?

The presentation layer usually remains platform-specific.

This includes:

  • Navigation
  • Layouts
  • Menus
  • Platform widgets
  • Accessibility features
  • Device-specific interactions

As a result:

Android users receive an Android experience.

Apple users receive an Apple experience.

Whilst:

Business Behaviour

Remains Consistent

across both environments.

Architecture Overview

A simplified Kotlin Multiplatform architecture might resemble:

Native Android UI

        ↓

Shared Business Logic

Shared Networking

Shared Data Models

Shared Validation

        ↑

Native Apple UI

The native interfaces communicate with a shared application core.

This shared core becomes the single source of truth for application behaviour.

Core Architectural Components

Shared Business Logic

Business logic defines how the application behaves.

Examples include:

  • Pricing calculations
  • Eligibility checks
  • Workflow rules
  • Transaction processing
  • Security policies

Implementing these rules once helps ensure consistent behaviour across platforms.

Shared Networking

Most modern applications communicate with remote services.

Sharing networking components provides:

  • Consistent API usage
  • Reduced implementation effort
  • Improved testing
  • Simplified maintenance

Shared Data Models

Many applications use identical data structures on every platform.

Examples include:

  • Customers
  • Orders
  • Products
  • Accounts
  • Reports

Kotlin Multiplatform allows these definitions to be shared.

Shared Validation

Validation is an ideal candidate for reuse.

For example:

Password Rules

Email Validation

Account Verification

Transaction Limits

should generally behave identically regardless of device.

Native Presentation Layer

The user interface remains native.

This allows each platform to:

  • Follow platform conventions
  • Support accessibility features
  • Adopt operating system enhancements
  • Provide familiar user experiences

A Physical Analogy

The Shared Logic Model can be compared to a franchise operation.

Shared UI Architecture

Imagine a chain of restaurants where every location is identical.

Same Building

Same Layout

Same Decor

Same Menu

The goal is consistency everywhere.

Shared Logic Architecture

Now imagine a franchise model.

Shared Recipes

Shared Suppliers

Shared Accounting

Shared Food Safety Rules

Shared Training

However:

Different Buildings

Different Decorations

Different Seating Arrangements

Customers experience something unique to their location.

The business still operates according to common rules.

This closely resembles Kotlin Multiplatform's architectural philosophy.

Comparing Architectural Models

Traditional Native Development

Android

    UI
    Logic
    Networking
    Data

iOS

    UI
    Logic
    Networking
    Data

Advantages:

  • Maximum control
  • Native experience
  • Direct platform integration

Disadvantages:

  • Significant duplication
  • Higher maintenance costs

Shared UI Architecture

Shared UI

Shared Logic

Shared Data

        ↓

Android

iOS

Advantages:

  • Maximum reuse
  • Consistent presentation
  • Faster feature delivery

Disadvantages:

  • Less platform individuality
  • Greater dependence on framework rendering

Shared Logic Architecture

Native Android UI

        ↓

Shared Logic

Shared Data

        ↑

Native Apple UI

Advantages:

  • Native user experiences
  • Reduced duplication
  • Shared business behaviour

Disadvantages:

  • Separate UI development remains necessary
  • More architectural planning required

Advantages of Kotlin Multiplatform

Reduced Duplication

Logic is written once and reused across platforms.

Native User Experience

Each platform retains its familiar look and behaviour.

Consistent Business Rules

Business behaviour remains aligned regardless of device.

Long-Term Maintainability

Changes to shared logic automatically benefit every supported platform.

Strong Architectural Separation

Clear boundaries often encourage better software design.

Business logic remains separate from presentation concerns.

Trade-Offs and Challenges

UI Development Remains Separate

Kotlin Multiplatform does not eliminate all duplication.

Interfaces must still be developed for each platform.

Additional Architectural Complexity

Shared libraries introduce:

  • Dependency management
  • Interface contracts
  • Platform integration requirements

Team Coordination

Successful implementations often require close collaboration between platform teams.

Learning Curve

Developers must understand:

  • Kotlin
  • Platform-specific development
  • Shared architecture patterns

Comparing Kotlin Multiplatform with Flutter

Flutter and Kotlin Multiplatform are frequently compared, but they optimise for different objectives.

Flutter

Typically shares:

  • UI
  • Logic
  • Data access

Its goal can be summarised as:

Maximum Sharing

Benefits include:

  • Consistency
  • Rapid delivery
  • High code reuse

Kotlin Multiplatform

Typically shares:

  • Business logic
  • Data models
  • Networking

Its goal can be summarised as:

Native Experience
With
Shared Behaviour

Benefits include:

  • Native interfaces
  • Platform familiarity
  • Shared business rules

Neither approach is universally superior.

Each represents a different architectural strategy.

Typical Use Cases

Kotlin Multiplatform is particularly attractive for:

  • Banking applications
  • Financial services
  • Enterprise platforms
  • Healthcare systems
  • Insurance platforms
  • Complex business applications

These systems often contain substantial business logic that must remain consistent across platforms.

Common Misconceptions

"Kotlin Multiplatform Is Just Another Flutter Competitor"

Not entirely.

Flutter focuses on sharing the entire application experience.

Kotlin Multiplatform focuses primarily on sharing application behaviour.

The architectural goals differ.

"Kotlin Multiplatform Is Basically Native Development"

Not entirely.

Although user interfaces remain native, considerable portions of the application are shared.

It is more accurately viewed as a hybrid approach.

"More Sharing Is Always Better"

Not necessarily.

The optimal architecture depends upon:

  • Business requirements
  • Team structure
  • Long-term maintenance goals

Good architects optimise for value rather than code-sharing percentages.

Practical Guidance

Kotlin Multiplatform is often well-suited when:

  • Business logic is complex
  • Long-term maintenance is important
  • Native user experiences are desirable
  • Multiple platforms must behave consistently

It may be less attractive when:

  • User interface development dominates effort
  • Maximum code sharing is the primary objective
  • Teams lack Kotlin expertise

The Shared Truth Model

One way to view Kotlin Multiplatform is as a mechanism for sharing truth.

The architecture does not seek to make every screen identical.

Instead, it seeks to ensure that:

  • The same rules apply
  • The same calculations occur
  • The same validation succeeds
  • The same business outcomes result

regardless of platform.

The user experiences may differ.

The underlying truth remains consistent.

Conclusion

Kotlin Multiplatform represents a different interpretation of cross-platform development.

Rather than attempting to standardise the entire application, it focuses on the parts of the system that often matter most to the organisation: the business rules, integrations, data structures, and application behaviour.

By retaining native user interfaces, Kotlin Multiplatform acknowledges that platforms have different conventions, expectations, and strengths.

Its goal is not to make Android and Apple applications identical.

Its goal is to ensure they behave consistently whilst still feeling at home on their respective platforms.

In many ways, Kotlin Multiplatform is less concerned with sharing screens and more concerned with sharing truth.

For organisations whose greatest asset lies in their business logic rather than their presentation layer, this can be a remarkably powerful architectural model.