Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8161279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:27:56+00:00 2026-06-06T18:27:56+00:00

I have the following classes/protocols: @interface Super @end @implementation Super @end @interface Sub1 @end

  • 0

I have the following classes/protocols:

@interface Super
@end
@implementation Super
@end
@interface Sub1
@end
@implementation Sub1
@end
@interface Sub2
@end
@implementation Sub2
@end

@protocol FooProtocol
- (void) foo;
@end
@interface Sub1 (FooCategory) <FooProtocol>
@end
@implementation Sub1 (FooCategory)
- (void) foo {}
@end
@interface Sub2 (FooCategory) <FooProtocol>
@end
@implementation Sub2 (FooCategory)
- (void) foo {}
@end
@interface Super (FooCategory) <FooProtocol>
@end
// Notice that there is no @implementation Super (FooCategory)

This allows me to write a function similar to this:

void callFoo(NSArray *supers) {
  for (Super *theSuper in supers) {
    [theSuper foo];
  }
}

Sub1 and Sub2 are Super‘s only two subclasses. I essentially want polymorphism in a category method. If I specify an @interface for Super, but provide no @implementation, clang doesn’t give me any warnings/errors.

Is this a really bad hack?

What are the potential downsides?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:27:57+00:00Added an answer on June 6, 2026 at 6:27 pm

    (Originally from a comment on zneak’s answer.)

    As explained in The Objective-C Programming Language, a method in a category truly becomes part of the targeted class at runtime – which is why it can be dangerous to clobber an existing method, and why the behavior of multiple categories implementing the same method is undefined. Once the method is installed, it’s really no different from something that was there initially:

    Category methods can do anything that methods defined in the class proper can do. At runtime, there’s no difference. The methods the category adds to the class are inherited by all the class’s subclasses, just like other methods.

    It’s okay to have a category on Super and categories on its subclasses implementing the same method, and it’ll work exactly like if they were part of the classes themselves. (Though I do recommend following zneak’s advice of implementing a stub method on Super to help with debugging if it ever gets invoked accidentally.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes: public interface Emailer {} @Named public class RealEmailer implements
I have following classes. class A { public: void fun(); } class B: public
I have the following classes defined: public interface Thingy { ... } public class
I have the following classes: class A { public: virtual void f() {} };
I have following Classes and interfaces.. public interface ITaggable { ICollection<Tag> Tags { get;
I have the following classes class Parent { virtual void doStuff() = 0; };
I have the following classes public interface InterfaceBase { } public class ImplementA:InterfaceBase {
Imagine we have following classes: public interface MyInterface<T> { List<T> getList(T t); } abstract
I have the following classes: public interface IRenderer<T> { string Render(T obj); } public
I have the following classes: public interface IWaybillDocument { long DocumentId { get; set;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.