title: Is it an acceptable pattern for an init method to return an object of a different type?
body: <p>I'm working on bugfixes for some existing objective-c code and came across something I thought strange:  </p>
  
  <pre><code>@interface ClassA : UIView
  ...
  
  static ClassA* oldSelf = nil;
  
  @implementation
  - (id)initWithFrame:(CGRect)frame {
      oldSelf = self;
      self = [[ClassB alloc] initWithFrame:(CGRect)frame]; // xcode warns: Incompatible pointer types assigning to "ClassA *" from "ClassB *"
      //       ^^^^^^ Is this ok?
      [oldSelf release];
      return self;
  }
  
  
  @interface ClassB : UIView
  ...
  
  @implementation
  - (id)initWithFrame:(CGRect)frame {
      self = [super initWithFrame:frame];
      return self;
  }
  </code></pre>
  
  <p>This whole thing is wrapped up into a <strong>static library</strong>.  The public gets the lib.a file and ClassA.h
  In code using the library, This occurs:</p>
  
  <pre><code>#import "ClassA.h"
  
  ...
  
  // useage
  ClassA *myA = [[ClassA alloc] initiWithFrame:CGRectMake(0,0,100,100)];
  ...
  </code></pre>
  
  <p>So we got an initializer for ClassA that actually returns an unrelated class.  ClassA and ClassB respond to the same messages so it compiles and runs.  Seems like ClassA is being used to  obscure some features exposed in ClassB?</p>
  
  <p>I'm curious if this is acceptable behavior, and if it's a known pattern, what is it called?  Are there any side effects to this setup?</p>
  
  <p>=========================================================</p>
  
  <p>Thanks for everyone's answers!  I think I've got it...  in short, not a normal pattern, and not exactly a good idea</p>
  
  <ul>
  <li>Kind of like a "class cluster"(abstract factory), but not quite, because a common abstract class should be returned.  And since the code doesn't seem to ever intend to return anything but a ClassB object, probably not what the original author was thinking.</li>
  <li>More like a proxy, but implemented wrong.  ClassA should hold a private instance of ClassB and pass messages between the two.</li>
  </ul>
  
  <p>=========================================================</p>
  
  <p>Edited: added "oldSelf" parts...</p>
  
  <p>Edited: added static library details...</p>
  
  <p>Edited: added a blurb about the accepted answer...</p>