title: AbstractFactory pattern in objective-c
body: <p>I'm just trying to learn objectives-c.</p>
  
  <p>I've seen wikipedia example for <a href="http://en.wikipedia.org/wiki/Abstract_factory_pattern#Objective-C" rel="nofollow">AbstractFactory</a> pattern, across different languages.</p>
  
  <p>Here's the Button definition:</p>
  
  <pre><code>@protocol Button
  - (void)paint;
  @end
  
  @interface WinButton : NSObject &lt;Button&gt;
  @end
  </code></pre>
  
  <p>Here's a factory:</p>
  
  <pre><code>@implementation WinFactory
  - (id)createButton {
      return [[[WinButton alloc] init] autorelease];
  }
  @end
  </code></pre>
  
  <p>As far as I kwnow, obj-c's <code>id</code> keyword should be something like C#'s <code>var</code> or C++11's <code>auto</code>,
  right?</p>
  
  <p>So I my question is:</p>
  
  <p>why let the factory return a generic object of a not specified type?
  Is this an error (that let factory return something other that is not a Button) or is there any reason to do that?</p>
  
  <p>I'd write a factory this way:</p>
  
  <pre><code>@implementation WinFactory
  - (id&lt;Button&gt;)createButton {
      return [[[WinButton alloc] init] autorelease];
  }
  @end 
  </code></pre>
  
  <p>am I wrong?</p>