关于 Flow-Based Programming 编程的概念大家有接触过吗?
相关介绍网址:
1. http://noflojs.org/example/
2. http://www.jpaulmorrison.com/fbp/index.shtml
它是一种很好的组件编程方式,基本概念就是
1. 把可复用的代码抽象成组件,组件有 输入、控制、输出端口。
2. 用 DSL(领域专用语言)把不同组件的输入、输出端口连起来,组合出复杂的功能。控制端口用于初始设置组件的功能。
3. 最后由 Flow - Based runtime (引擎)解析 DSL ,让所有组件一起运行完成你所需的功能。
看上面两个网址的介绍,这个概念 还可以应用在嵌入式设备上,尤其是适用于智能家居行业这种需求复杂多变的场景里。如下是控制 AR.Drone 起飞,降落的例子
// Start by connecting to drone. We could provide IP here
'' -> IP Connect(ardrone/Connect)
// Tell drone to take off
Connect() CLIENT -> CLIENT Takeoff(ardrone/Takeoff)
// Tell drone to land
Takeoff() CLIENT -> CLIENT Land(ardrone/Land)
// And that is all, folks!
Land() CLIENT -> IN End(core/Drop)
有兴趣的人欢迎留言~