kotlin 密封类_如何使用Kotlin密封类进行状态管理

本文介绍了如何利用Kotlin的密封类进行状态管理,通过密封类可以更有效地控制和处理程序的不同状态。
摘要由CSDN通过智能技术生成

kotlin 密封类

介绍 (Introduction)

State management is one of the critical aspects of any platform while the product is growing.

在产品不断发展的同时,状态管理是任何平台的关键方面之一。

One of my apps in the Google Play store has a payment screen with multiple payment gateways. Users can make the payment with any gateway.

我在Google Play商店中的一个应用程序具有一个带有多个付款网关的付款屏幕。 用户可以使用任何网关进行付款。

After the payment, there will be an acknowledgment pop-up stating the status of the purchase.

付款后,将弹出确认消息,说明购买状态。

问题 (Problem)

In the beginning, we only had Google Play Billing (for in-app purchases). At that time, it was easy to maintain states like success, failure, retry, and acknowledgment. Recently, we decided to add PayU and Stripe as additional payment gateways, and that’s where the problem of state management started.

最初,我们只有Google Play结算(用于应用内购买)。 那时,维护successfailureretryacknowledgment等状态很容易。 最近,我们决定将PayU和Stripe添加为附加的支付网关,这就是状态管理的开始。

One thing we’re sure of is we’ll add more payment gateways in the future, so maintaining different flows for each gateway will drain the code-management system. So we decided to create a flow that works uniquely for all gateways.

我们确定的一件事是,将来我们将添加更多的支付网关,因此,为每个网关维护不同的流量将耗尽代码管理系统。 因此,我们决定创建一个对所有网关都唯一起作用的流。

That’s when we found an excellent talk (resource added at the end of the article) by Patrick Cousins at the Kotlin Conference 2018 about sealed classes and how he used them to maintain states during the login of his app.

那时我们在帕特里克·考辛斯(Patrick Cousins)在2018年Kotlin会议上找到了关于密封类以及在登录应用程序期间如何使用它们维护状态的精彩演讲(文章末尾添加了资源)。

(Solution)

So we’re convinced we need to deal with the state management of sealed classes. Befo

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值