Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is the Abstract factory implementation for Objective C.</p> <pre><code>// Usage BrandingFactory * factory = [BrandingFactory factory:Sierra]; UIView * view = [factory brandedView]; UIButton * button = [factory brandedMainButton]; UIToolbar * toolbar = [factory brandedToolbar]; ____________________________________________ // BrandingFactory.h // AbstractFactory #import &lt;Foundation/Foundation.h&gt; typedef enum ouputTypes { Acme, Sierra } OutputTypes; @interface BrandingFactory : NSObject { } + (BrandingFactory *) factory: (OutputTypes)type; - (UIView *) brandedView; - (UIButton *) brandedMainButton; - (UIToolbar *) brandedToolbar; @end ___________________________________________________ // BrandingFactory.m // AbstractFactory #import "BrandingFactory.h" #import "AcmeBrandingFactory.h" #import "SierraBrandingFactory.h" @implementation BrandingFactory + (BrandingFactory *) factory:(OutputTypes)type { if (type == Sierra) { return [[[SierraBrandingFactory alloc] init] autorelease]; } else if (type == Acme) { return [[[AcmeBrandingFactory alloc] init] autorelease]; } return nil; } - (UIView *) brandedView { return nil; } - (UIButton *) brandedMainButton { return nil; } - (UIToolbar *) brandedToolbar { return nil; } @end ________________________________________ // SierraBrandingFactory.h // AbstractFactory #import &lt;Foundation/Foundation.h&gt; #import "BrandingFactory.h" @interface SierraBrandingFactory : BrandingFactory { } - (UIView*) brandedView; - (UIButton*) brandedMainButton; - (UIToolbar*) brandedToolbar; @end // SierraBrandingFactory.m // AbstractFactory #import "SierraBrandingFactory.h" #import "SierraView.h" #import "SierraMainButton.h" #import "SierraToolbar.h" @implementation SierraBrandingFactory - (UIView*) brandedView { // returns a custom view for Sierra return [[[SierraView alloc] init] autorelease]; } - (UIButton*) brandedMainButton { // returns a custom main button for Sierra return [[[SierraMainButton alloc] init] autorelease]; } - (UIToolbar*) brandedToolbar { // returns a custom toolbar for Sierra return [[[SierraToolbar alloc] init] autorelease]; } @end ________________________________________ // AcmeBrandingFactory.h // AbstractFactory #import &lt;Foundation/Foundation.h&gt; #import "BrandingFactory.h" @interface AcmeBrandingFactory : BrandingFactory { } - (UIView *) brandedView; - (UIButton *) brandedMainButton; - (UIToolbar *) brandedToolbar; @end // AcmeBrandingFactory.m // AbstractFactory #import "AcmeBrandingFactory.h" #import "AcmeView.h" #import "AcmeMainButton.h" #import "AcmeToolbar.h" @implementation AcmeBrandingFactory - (UIView *) brandedView { // returns a custom view for Acme return [[[AcmeView alloc] init] autorelease]; } - (UIButton *) brandedMainButton { // returns a custom main button for Acme return [[[AcmeMainButton alloc] init] autorelease]; } - (UIToolbar *) brandedToolbar { // returns a custom toolbar for Acme return [[[AcmeToolbar alloc] init] autorelease]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload