title: Abstract class in Objective-C
body: <p>I need your help. Following problem in Objective-C:</p>
  
  <pre><code>// Robot.h
  @protocol RobotProtocol &lt;NSObject&gt;
      -(void)doWork;
  @end
  
  @interface Robot : NSObject 
  
  
  // Rob1 sublass of class Robot
  // rob1.h
  @interface Rob1 : Robot &lt;RobotProtocol&gt;
  
  // rob1.m
  @implementation
  -(void)doWork
  {
      // print 'robot 1'
  }
  
  
  // Rob2 sublass of class Robot
  // rob2.h
  @interface Rob2 : Robot &lt;RobotProtocol&gt;
  
  // rob2.m
  @implementation
  -(void)doWork
  {
      // print 'robot 2'
  }
  
  
  
  // Task.h
  @interface Task : NSObject
  {
      Robot *rob;
  }
  
  
  // Task.m
  @implementation
  - (id)init
  {
      if ([super init]) {
          rob = [[Rob1 alloc] init]; // or Rob2 !!
      }
      return self;
  }
  
  -(void)doSomething
  {
      [rob doWork]; // how to make sure, that this is implemented, depending on Rob1 or Rob2
  }
  </code></pre>
  
  <p>How should <code>Robot</code> and its subclasses be implemented, that <code>Robot *rob</code> can be one of the subclasses of Robot <code>rob1</code>, <code>rob2</code>, <code>...</code> and the method <code>doWork:(BOOL)val;</code> can be called? My first idea was to implement <code>Robot</code> as an abstract class, but unfortunately there are no abstract classes in Objective-C...</p>
  
  <p>At the moment I am using a protocol, but I am not confident. Because it is not sure, that doWork is implemented, the compiler complains about</p>
  
  <blockquote>
    <p>'Robot' may not respond to 'doWork'</p>
  </blockquote>
  
  <p>Thank you for your ideas.</p>