抽象产品A   Product.h :


//
//  ProductA.h
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import <Foundation/Foundation.h>
@protocol ProductA <NSObject>
- (void)fun;
@end


具体产品A1  ProductA1.h  &  ProductA1.m :


//
//  ProductA1.h
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ProductA.h"
@interface ProductA1 : NSObject <ProductA>
@end


//
//  ProductA1.m
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import "ProductA1.h"
@implementation ProductA1
- (void)fun
{
    NSLog(@"ProductA1 -> fun()");
}
@end


具体产品A2  ProductA2.h  &  ProductA2.m :


//
//  ProductA2.h
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ProductA.h"
@interface ProductA2 : NSObject <ProductA>
@end


//
//  ProductA2.m
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import "ProductA2.h"
@implementation ProductA2
- (void)fun
{
    NSLog(@"ProductA2 -> fun()");
}
@end


抽象产品B  ProductB.h :


//
//  ProductB.h
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import <Foundation/Foundation.h>
@protocol ProductB <NSObject>
- (void)fun;
@end


具体产品B1  ProductB1.h  &  ProductB1.m :


//
//  ProductB1.h
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ProductB.h"
@interface ProductB1 : NSObject <ProductB>
@end


//
//  ProductB1.m
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import "ProductB1.h"
@implementation ProductB1
- (void)fun
{
    NSLog(@"ProductB1 -> fun()");
}
@end


具体产品B2  ProductB2.h  &  ProductB2.m :


//
//  ProductB2.h
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ProductB.h"
@interface ProductB2 : NSObject <ProductB>
@end


//
//  ProductB2.m
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import "ProductB2.h"
@implementation ProductB2
- (void)fun
{
    NSLog(@"ProductB2 -> fun()");
}
@end


抽象工厂 Factory.h :


//
//  Factory.h
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ProductA.h"
#import "ProductB.h"
@protocol Factory <NSObject>
- (id<ProductA>) getProductA;
- (id<ProductB>) getProductB;
@end


具体工厂1  Factory1.h & Factory1.m :


//
//  Factory1.h
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Factory.h"
@interface Factory1 : NSObject <Factory>
@end


//
//  Factory1.m
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import "Factory1.h"
#import "ProductA1.h"
#import "ProductB1.h"
@implementation Factory1
- (id<ProductA>) getProductA
{
    return [[ProductA1 alloc] init];
}
- (id<ProductB>) getProductB
{
    return [[ProductB1 alloc] init];
}
@end


具体工厂2  Factory2.h &  Factory2.m :


//
//  Factory2.h
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Factory.h"
@interface Factory2 : NSObject <Factory>
@end


//
//  Factory2.m
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import "Factory2.h"
#import "ProductA2.h"
#import "ProductB2.h"
@implementation Factory2
- (id<ProductA>) getProductA
{
    return [[ProductA2 alloc] init];
}
- (id<ProductB>) getProductB
{
    return [[ProductB2 alloc] init];
}
@end


测试 main.m :


//
//  main.m
//  FactoryObc
//
//  Created by hejinlai on 13-8-8.
//  Copyright (c) 2013年 yunzhisheng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Factory.h"
#import "Factory1.h"
#import "Factory2.h"
int main(int argc, const char * argv[])
{
    @autoreleasepool {
              
        id<Factory> factory = [[Factory1 alloc] init];
        id<ProductA> prodcutA = [factory getProductA];
        id<ProductB> prodcutB = [factory getProductB];
        [prodcutA fun];
        [prodcutB fun];
               
        id<Factory> factory2 = [[Factory2 alloc] init];
        id<ProductA> prodcutA2 = [factory2 getProductA];
        id<ProductB> prodcutB2 = [factory2 getProductB];
        [prodcutA2 fun];
        [prodcutB2 fun];
               
    }
    return 0;
}


测试结果:


2013-08-08 15:35:19.728 FactoryObc[13237:303] ProductA1 -> fun()

2013-08-08 15:35:19.730 FactoryObc[13237:303] ProductB1 -> fun()

2013-08-08 15:35:19.731 FactoryObc[13237:303] ProductA2 -> fun()

2013-08-08 15:35:19.731 FactoryObc[13237:303] ProductB2 -> fun()