业务逻辑和UI逻辑之间有什么区别? [英] What are the difference between business logic and UI logic?

查看:245
本文介绍了业务逻辑和UI逻辑之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 flutter 中的状态管理,并且大多数时候我遇到的单词是业务逻辑 ui逻辑和一段时间的表示逻辑,当人们用不同的语言解释它时,我在互联网上进行了搜索,但我无法更好的理解是,有人可以以示例的形式显示这三种逻辑并解释得很干净和容易吗?

I am learning state management in flutter and most of the time I encounter with words business logic ui logic and some time presentation logic, I searched it on the internet as people explain it in different languages, I couldn't get a better understanding, Could someone please show these three types of logic in the form of an example and explain it very clean and easy?

推荐答案

使用库时,将其与代码的关键部分(业务逻辑)分开是我们的责任和使命。

例如,在清洁架构中,遵循这些原则的目标是将关注点和角色分离为以下类别:

1)UI(用户界面)

2)格式化程序(格式,法律部分,内容)

3)业务逻辑(业务规则)

4)数据(可以在内存中,如API或在线网络数据库或l ocal持久存储/数据库)

When we use a library, it is our responsibility and mission to separate it from critical parts of our code, which is the Business Logic.
In Clean Architecture, for example, which respects those principles, the goal is to separate the concerns and roles that can be categorized into:
1) UI (User Interface)
2) Formatter (the format, the legal part, the content)
3) Business Logic (the Business rules)
4) Data (can be in-memory, networks like APIs or Online Database or local persistent store/database)

在UI部件上使用跨平台/多平台的解决方案(如扑朔迷离)可能比在业务上更具逻辑性部分。

业务逻辑不会经常更改,但是在开发UI时可能会经常更改。

例如,对于联网呼叫,我们可以自己实现此层或依赖于知名库。如果明天出现了一个更好的新版本,我们只需要替换该层的实现,而不会影响整个模块或项目。

有时,当客户说应用程序需要具有相同功能的新UI时,可能是在大多数情况下仅在UI上进行更改的方式构建的,而不会影响其背后功能的逻辑。

在动荡的情况下,请考虑增加印刷计数的基本应用示例,逻辑应该分开(也许在其他类/文件中),因此,如果我们需要将按1,2,3次按更改为a,b,c ...次按,则唯一的业务逻辑应更改。 >
请遵循以下示例:

Using cross-platform/multi-platform solutions like a flutter on the UI part can be a bit more logical than on the Business part.
The Business Logic doesn't change frequently, but there might be frequent change wile developing UI.
For example, for networking calls, we can either implement this layer by ourselves or depend on a well-known library. If tomorrow a new better one shows up, we only need to replace the implementation of our layer without impacting the whole module or project.
Sometimes when a client says that app needs new UI with the same features, The might have been built at the way there must only be a change in UI mostly, without affecting the logic of features behind.
In the context of flutter, consider the example of a basic app of increment of press count, The logic should be separated (maybe in other class/file) so if we need to change pressing 1,2,3 times press to a,b,c... times press, the only business logic should be changed.
Follow The example below:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 65;
  String hello = "a";

  // the only business logic change will be here...No UI change require
  void _incrementCounter() {
    setState(() {
      hello = String.fromCharCode(_counter);
      if(_counter!=90)
        _counter++;
      else
        _counter = 65;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$hello',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

仍然不明白,请参考以下内容:

(1)(2)(3)

Still not getting the idea, refer below:
(1), (2), (3)

这篇关于业务逻辑和UI逻辑之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆