1

coming from a java background when you make abstract classes, and someone uses them and over rides them with their values: in objective c... how do you make an abstract class in a static library for someone to open and override? thanks

edit:more specifically, how can they implement the method in their method and over ride the values to use for themself(s)? Again sorry if this is easy, im from a java backgrund

  • possible duplicate of [Creating an abstract class in Objective C](http://stackoverflow.com/questions/1034373/creating-an-abstract-class-in-objective-c) – Sergey Kalinichenko Feb 28 '13 at 15:25
  • Objective-C is much more dynamic than Java, and a formal abstract class would not make much sense, given that methods in theory can be added to a class at runtime. Cocoa and Java don't mix that well, in fact Apple ditched the original Cocoa-Java implementation due to too many differences in philosophy between the two languages and frameworks. – Monolo Feb 28 '13 at 15:33

3 Answers3

1

Unlike some other languages, Objective-C does not have syntax to mark classes as abstract, nor does it prevent you from creating an instance of an abstract class.

Simply say in the docs that it's intended to be subclassed and not used as such.

Rikkles
  • 3,372
  • 1
  • 18
  • 24
1

Cocoa doesn’t provide anything called abstract. We can create a class abstract which gets check only at runtime, compile time this is not checked.

Here is just a try :

@interface AbstractClass : NSObject
@end

@implementation AbstractClass
+ (id)alloc{
    if (self == [AbstractClass class]) {
        NSLog(@"Abstract Class cant be used");
    }
    return [super alloc];
@end

NOTE: This is not compiler checked.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • i see but how would someone from a library implement this – Gurinder Singh Feb 28 '13 at 15:41
  • First of all, this helps to give u an abstract class only at runtime, not at compile time, even if you go to make an object it will be creeated. So what is the benefit of this??? **Its better to change your design if you really want an abstract class.** – Anoop Vaidya Feb 28 '13 at 15:43
1

Coming from a Java background myself, I was looking for the same thing when I first started out with Objective-C. I found this answered my question:

Creating an abstract class in Objective-C

Short answer, there is no abstract class (at least in the Java context) in Objective-C.

Community
  • 1
  • 1
Jay Q.
  • 4,979
  • 3
  • 33
  • 36