-3

Is abstraction possible in objective c, if yes then how? If no, then how is objective c fulfilling this oops concept?

saurabh
  • 259
  • 1
  • 3
  • 11
  • 3
    Yes. Lots of ways. What did you look at so far? Do you have a more specific question? – Aaron Brager Mar 22 '15 at 16:55
  • 2
    You know those files that have names ending in `.h`? Those describe the interfaces, and are distinct from the implementation. – pjs Mar 22 '15 at 16:59
  • Is it possible for you to place one of these "many ways".... I was just try to find out the way it is done in c++.... an abstract class... – saurabh Mar 22 '15 at 17:03
  • We cannot create an instance of an abstract class... and by which way is this possible in .h files, I mean can you restrict developer from creating an instance of the class however implementing its method....? – saurabh Mar 22 '15 at 17:05
  • possible duplicate of [Creating an abstract class in Objective C](http://stackoverflow.com/questions/1034373/creating-an-abstract-class-in-objective-c) – NobodyNada Mar 22 '15 at 17:08
  • Nope this doesnt give answer to my question....We cannot create an instance of an abstract class by oops convention.... – saurabh Mar 22 '15 at 17:18
  • And for .h files we can always create an instance, so I just wanted to know how to create an abstract class in objective c..I have edited my question... – saurabh Mar 22 '15 at 17:20
  • @saurabh There are many ways to accomplish abstraction. You seem to think that abstraction is equivalent to having abstract classes. It's not. Abstraction is the separation of interface and implementation. You might want to look at Objective C's protocols. – pjs Mar 22 '15 at 17:52

1 Answers1

2

The language does not support abstract classes in compile time.

Usually people achieve this by throwing an exception in a method that is allegaly abstract and was not defined like this:

[NSException raise:NSInternalInconsistencyException 
        format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)];

You can also use this most recently NickLockwood's macro: MustOverride

Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82