Erlang:在同一模块中定义多个行为?
问:我想了解在同一模块文件中定义多个行为的优缺点。
例如,
-module(someapp_sup).
-behavior(supervisor).
-behavior(application).
使用这种布局,我可以保存模块文件,同时不会在可维护性方面损失太多(整个应用程序是通过 someapp_sup:start()
启动的)。
Q: I'd like to have an idea of the pros and cons of defining multiple behaviors in the same module file.
E.g.
-module(someapp_sup).
-behavior(supervisor).
-behavior(application).
Using this sort of layout, I can save a module file whilst not loosing much on the maintainability side (the whole application is started through someapp_sup:start()
).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要行为中定义的回调不与另一个行为的回调发生冲突(例如,假设您定义了自己的行为),那么除了可能导致代码更加混乱之外,这样做没有任何问题。显然,您可以通过一些适当的注释并将代码合理地放置在文件中来遏制这种情况。
As long as the callbacks defined in the behavior don't conflict with a callback of another behavior (say you defined your own behavior, for example) then there's nothing wrong with doing this other than potentially more confusing code. Obviously you can curb that with some well placed comments and laying the code out sensibly in the file.