移植/重写这个库的正确方法是什么?
我正在尝试用 Objective-C 重写 Java 库。我想将其重写为 API,以便需要实现某些方法。我已经开始尝试重写代码,但遇到了一些问题。
Objective-C 支持抽象类吗?
如果不是,我应该编写协议,还是只使用我自己的类?我知道您可以标记所需的方法。
如果我写协议,如果我将所有协议分组到一个头文件中可以吗?或者最好的做法是不这样做?
如果我使用自己的类,有没有办法要求抽象方法的子类化?
I'm attempting to rewrite a Java library over in Objective-C. I'd like to rewrite it as an API so that certain methods are required to be implemented. I've begun to try to rewrite the code but I've run into a few questions.
Does Objective-C support abstract classes?
If not, should I be writing protocols, or just use my own classes? I know that you can mark methods required.
If I do write protocols, Would it be okay if I group all the protocols into one header file, or is it best practice not to?
If I use my own classes, is there a way to require subclassing of abstract methods?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Objective-C 中有编译器强制执行的抽象类,协议就是你所追求的。
为了便于阅读,我个人会将协议分成多个标头。
There are compiler enforced abstract classes in Objective-C, protocols are what you are after.
I would personally break the protocols out into multiple headers for legibility.
没有对创建抽象类的内置支持,但您可以通过重写
allocWithZone:
方法来实现。There is no built in support for creating abstract classes, but you can do it by overriding the
allocWithZone:
method.