开发者

Does the Mac App Store allow subclassing private methods?

The Mac App Store guidelines state:

Apps that use non-public APIs will be rejected

Does that include sub-classing public objects with method开发者_如何转开发s that aren't mentioned in their class' reference?


Apple has not been entirely consistent in this regard, but they have rejected some apps for this.


I would strongly recommend against it. You don't know if Apple will reject your app for it (so you have to go back and fix it), or if they will change the private method (maybe it won't exist in the future so your apps won't work as expected on future OS X versions (this applies to iOS as well), and then you will have to go back and fix it).

Either way, whether they approve or reject your app, it's a bad idea.

What are you trying to do exactly anyway? Maybe there is a better and safer way to do it.


Almost all (but the simplest) well designed object's will have have private API's. That is the whole idea of encapsulation.

My guess is that when you sub-class a framework class, your code is stil only calling the public API on that class therefore you are not yourself calling any private API's. If this was not the case then surely no one would be able to release any software using the Cocoa and Cocoa-touch frameworks.

If you subclass and deliberately call a private method then of course this would be a violation

Take this example

/*
 * This is a framework class that needs to be subclassed
 * it has one public method  - (void)save;
 * and one private method    - (void)doSomeWork;
 */
@interface FrameWorkClass : NSObject

- (void)save;

@end

@interface FrameWorkClass ()

//private 
- (void)doSomeWork;

@end

@implementation FrameWorkClass

- (void)save
{
  [self doSomeWork]; // Call to private method
}

@end

/*
 * This is our subclass of FrameWorkClass
 */
@interface MyClass : FrameWorkClass
// more methods
@end

If I do this

MyClass *myClass = [[MyClass alloc] init];
[myClass save];

the save method results in the private API method - (void)doSomeWork; being called. I did not call it directly the framework class did. If I had done this instead

MyClass *myClass = [[MyClass alloc] init];
[myClass doSomeWork];

Then I would be calling the private API directly which would be declined.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜