In this short tutorial we will implement the Delegation design pattern in two languages: Dart and Swift. During the process, we will learn what a mixin
in Dart is and compare the final implementation with the Swift version.
在这个简短的教程中,我们将以两种语言实现委托设计模式:Dart和Swift。 在此过程中,我们将学习Dart中的mixin
是什么,并将最终实现与Swift版本进行比较。
Mixin
s allow us to add functionality to Dart classes and reuse their code in different class hierarchies.
Mixin
允许我们向Dart类添加功能,并在不同的类层次结构中重用其代码。
The source code is available at the bottom of the article.
源代码位于文章底部。
开始吧 (Let’s Start)
Say we have two classes, one is Manager
, another is Worker
. Manager
’s responsibility is to send a command to the Worker
to perform certain work. On the completion of that work, the Worker
class sends the result back to the Manager
.
假设我们有两个班级,一个是Manager
,另一个是Wor