Skip to content

Instantly share code, notes, and snippets.

@subdigital
Created February 21, 2012 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subdigital/1877934 to your computer and use it in GitHub Desktop.
Save subdigital/1877934 to your computer and use it in GitHub Desktop.
factories for an inheritance tree
@interface Person : NSObject
@property (copy) NSString *name;
@end
@interface Customer : Person
@property (copy) NSString *status;
@end
[MFFactory defineFactoryForClass:[Person class] withBlock:^(id p){
[p setName:@"foo"];
}];
// this factory would automatically gain the behavior from the Person factory,
// because its class's super class has a factory already defined
[MFFactory defineFactoryForClass:[Customer class] withBlock:^(id c) {
[c setStatus:@"gold"];
}];
// or, more explicitly:
[MFFactory defineFactoryForClass:[Customer class] baseFactory:@"some_custom_factory" withBlock:^(id customer) {
...
}];
@casademora
Copy link

how about something like:

[MFFactoy defineFactory:@"Customer" whichIsA:@"Person" using:^(id customer){
    customer.ID = @"{random_id}";
    customer.firstName = @"first name {generated_uniqueness}";
}];

@subdigital
Copy link
Author

subdigital commented Feb 21, 2012 via email

@casademora
Copy link

  1. We don't need to use the class method ahead of time because we want to be able to have factories that are generated on the fly.
  2. .ID, and .firstName are set* messages that can be intercepted on the "FactoryObject" and only need a header with that method in order to work properly (ObjC is a little verbose in this case)

@casademora
Copy link

casademora commented Feb 21, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment