Build a portable business logic

Andrei Aleksandrov
3 min readOct 12, 2017

--

Hi!

Many developers want to have cross-platform applications, so that you can “write once, use everywhere”. That spends time of developers and project costs. It’s really good if you don’t care so much about OS-specific features (or don’t care about client software). One good thing is web applications where you can access your business logic everywhere. Most of applications are today “thin client”-like, but we have to think more about structure, graphic, effects and application architecture. That makes frontend also very complex. But not all applications fit into this model. And sometimes there are applications that you want to use without internet.

Sometimes you also want to use some OS-features (notifications, sensors, network information, etc.) and it’s cool that many cross-platform frameworks contain APIs for that and hide OS-specific logic. I love this. And if I will have few frontend-developers, I will use this approach. But “professional in everything is professional in nothing”: if you want to use newest and coolest features of OS, you need to use “recommended development environment”: .NET for Windows, Swift/Objective C for macOS or iOS, Java for Android.

What would be a good option for this approach, if your application needs to have a logic on the client, but uses many OS-specific features that are “hard reachable” from cross-platform framework? Then you need to have fully cross-platform business logic and OS-specific clients.

How?

Okay, we are a big company that is ready to have a team for each platform and we don’t produce web applications. I will think in terms of MVVM where we have model that is actually our logic. So, we need to make it cross-platform. What do we need to do?

  1. Create an OS-independent protocol of communication between model and viewmodel: the simplest example is a command-line interface. You can execute commands via GUI. But, you can also build something more complex
  2. To have a separate data model for model and viewmodel: viewmodel shouldn’t use any model units. It will help when you will try to port an application and create a UI in another language
  3. Use a stable language that can be accessed by every other language and can be used on every platform (My suggestion is to use native (C++, FPC, maybe Rust or Go) languages with many platforms supported)
  4. Your logic should be completely independent from the environment!

After that you will have a portable bunch of code and then you can create your clients incredibly fast.

Advantages

If you will take such approach (to have a “native” app for every platform), you will get:

  1. There is a simple relation that you should think about: timeOf(createNativeApp) < timeOf(createCrossPlatform) < timeOf(createMultipleNativeApps)
  2. You will find better specialists for concrete OS and it will also speed up your development process
  3. Bug finding and fixing is easier
  4. If you use “recommended platform” you will get the best instruments for creating applications and you will without problems use any API of OS

Problems

  1. You need more developers
  2. It’s problematic to share the code of “logic”, but possible

Some thoughts about native in cross-platform world

I see that cross-platform development grows very fast. There are many cool instruments: Electron, FMX, Xamarin, React Native and more. But I think that we will always need people who will need to build bridges between cross-platform and native. We have many same things in OSes, but sometimes we need to build something platform-specific. Plus, every platform has its own stack that is supported and is always growing with new libraries and features and I think that cross-platform frameworks don’t have so much power to integrate the whole functionality. But, companies can write plugins by yourself and don’t stop using cross-platform solutions!

That’s all for today!

--

--