使用Objective-C over C ++的优点是什么 [英] What are the advantages of using Objective-C over C++

查看:107
本文介绍了使用Objective-C over C ++的优点是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说过Objective-C,但我从来没有使用过。我很好奇所有人的意见,它是一般的,也与C + +。

I have heard mention of Objective-C but I have never used it myself. I was curious what everyones opinion of it was in general and also in relation to C++. Are there any types of projects where it would be more useful or less useful?

推荐答案

像许多其他人一样,我刚开始寻找在Obj-C由于iPhone。我做了很多C ++和C#,从我可以看到Obj-C有一个基本上不同的方法,OO,因为它添加Smalltalk类消息传递到C.像C ++它基本上仍然C兼容,但OO扩展允许您向任何对象发送任何消息。在这个意义上,它不是静态类型,如C ++和C#,对象可以做的事情是绑定到类。在Obj-C中,您可以向对象发送消息,即使它不支持它。

Like many others I've just started looking at Obj-C due to iPhone. I've done a lot of C++ and C# and from what I can see Obj-C has a basically different approach to OO in that it adds Smalltalk-like messaging to C. Like C++ it's basically still C-compatible but the OO extensions let you send any message to any object. In that sense it's not statically typed like C++ and C# where the things an object can do are tied to the class it is. In Obj-C you can send a message to an object even if it doesn't support it. The object can then forward it if it doesn't know what to do with it.

真的很酷的事情是,你可以在运行时添加接口(协议),并且你可以在运行时添加接口可以添加自己的处理程序,拦截和隐藏现有类的消息处理程序。

The really cool thing is that you can add interfaces (protocols) at runtime and you can add your own handlers that intercept and hide message handlers for existing classes.

总而言之,在消息处理方面有更多的灵活性,做在Ruby或Smalltalk。无论是将这种类型的OO嫁接到C上还是不是一个好主意,我不能告诉,在某些方面,C ++方法更好地与C的原始想法啮合,但另一方面,Obj-C OO方法更多什么OO纯粹主义者喜欢。

All in all there's a lot more flexibility when it comes to message handling, more like what you would do in Ruby or Smalltalk. Whether it's a good idea to have this type of OO grafted onto C or not I can't tell yet, in some ways the C++ approach meshes better with the original idea of C but on the other hand the Obj-C OO approach is more what OO purists like.

这篇关于使用Objective-C over C ++的优点是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆