[Review design mode in IOS]-abstractfactory

Source: Internet
Author: User
View code

 
@ InterfaceBrandingfactory: nsobject
{

}

+ (Brandingfactory *) factory;

-(Uiview *) brandedview;
-(Uibutton *) brandedmainbutton;
-(Uitoolbar *) brandedtoolbar;

@ End
View code

 # Define Use_acme

@ Implementation Brandingfactory

+ (Brandingfactory *) Factory
{
# If Defined (use_acme)
Return [[Acmebrandingfactory alloc] init] autorelease];
# Elif Defined (use_siider)
Return [[Sierrabrandingfactory alloc] init] autorelease];
# Else
Return Nil;
# Endif
}

-(Uiview *) brandedview
{
Return Nil;
}

-(Uibutton *) brandedmainbutton
{
Return Nil;
}

-(Uitoolbar *) brandedtoolbar
{
Return Nil;
}

@ End

==================================

View code

 
@ InterfaceSierrabrandingfactory: brandingfactory
{

}

-(Uiview *) brandedview;
-(Uibutton *) brandedmainbutton;
-(Uitoolbar *) brandedtoolbar;
View code

 @ Implementation Sierrabrandingfactory

-(Uiview *) brandedview
{
// Returns a custom view for siider
Return [[Sierraview alloc] init] autorelease];
}

-(Uibutton *) brandedmainbutton
{
// Returns a custom main button for siider
Return [[Sierramainbutton alloc] init] autorelease];
}

-(Uitoolbar *) brandedtoolbar
{
// Returns a custom toolbar for siider
Return [[Sierratoolbar alloc] init] autorelease];
}

@ End

==================================

View code

 
@ InterfaceAcmebrandingfactory: brandingfactory
{

}

-(Uiview *) brandedview;
-(Uibutton *) brandedmainbutton;
-(Uitoolbar *) brandedtoolbar;
View code

 @ 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

==================================

Client:

View code

 brandingfactory * factory = [brandingfactory factory]; 
uiview * view = [factory brandedview];
uibutton * button = [factory brandedmainbutton];
uitoolbar * toolbar = [factory brandedtoolbar];
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.