Not Sure about implicit interface implementation

blov · · 401 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m just learning GO and i cant help feeling that it&#39;s over simplify things sometimes. For instance implicit interface implementation removes the obligation from the implementor of a interface to understand what the are implementing, just assuming that types that have the some method signiture that are the same can be used polymorphicaly is a bit dangerious. For instance: cake.Eat(me) lion.Eat(me) calling these methods may result in very different experiences.</p> <hr/>**评论:**<br/><br/>dsymonds: <pre><p>In theory, yes, it could cause problems.</p> <p>In practice, it pretty much never does.</p></pre>bkeroack: <pre><p>That&#39;s a weird example. The cake isn&#39;t eating you.</p></pre>quiI: <pre><p>In what way does </p> <pre><code>MyClass implements Eater </code></pre> <p>Giving you any more information? With most traditional statically typed languages all you&#39;re getting as an implementer of an interface are clues in the form of types. </p> <p>You still get this with Go, just without the boilerplate and you get a lot more flexibility</p></pre>cs-guy: <pre><p>I had the same worry when I first started learning Go. As I became comfortable with the language the worry went away and the benefits of implicit interface implementation became more clear. Now I believe it is one of the best aspects of the language. It allows for better decoupling of types and packages, which is a very good thing.</p></pre>GopherFromHell: <pre><p>having implicit interfaces also has the effect of making interfaces smaller and more useful by consequence.</p></pre>kavehmz: <pre><p>Just adding to reasons,</p> <p>In explicit implementations sometime you spend a lot of time in beginning of project to design your interfaces. At that time you might not know the best design you need. So you will end up doing more refactoring.</p> <p>In Go&#39;s implicit way, you can define your interfaces later in the project or add interfaces to old code without extensive refactoring.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

401 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传