Created
February 21, 2012 18:17
-
-
Save subdigital/1877934 to your computer and use it in GitHub Desktop.
factories for an inheritance tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) { | |
... | |
}]; |
Is there really a case where you wouldn't want the inherited factory? I think the only explicit case we'd want is if you named a factory specifically and want the subclass to use the named factory as its base.
…On Feb 21, 2012, at 3:04 PM, Saul Mora wrote:
how about something like:
[MFFactoy defineFactory:@"Customer" whichIsA:@"Person" using:^(id customer){
customer.ID = @"{random_id}";
customer.firstName = @"first name {generated_uniqueness}";
}];
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1877934
- 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.
- .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)
I honestly don't know. I'll talk with Eloy tomorrow and try to determine why inheritance is desired.
I haven't done enough with factories to get a feel for what goes wrong in the syntax to say otherwise for now...
Another solution is to just fix factory girl and do this stuff using MacRuby...I'm sure Eloy wouldn't mind that :)
…On Feb 21, 2012, at 10:08 PM, Ben Scheirman wrote:
Is there really a case where you wouldn't want the inherited factory? I think the only explicit case we'd want is if you named a factory specifically and want the subclass to use the named factory as its base.
On Feb 21, 2012, at 3:04 PM, Saul Mora wrote:
> how about something like:
>
> [MFFactoy defineFactory:@"Customer" whichIsA:@"Person" using:^(id customer){
> customer.ID = @"{random_id}";
> customer.firstName = @"first name {generated_uniqueness}";
> }];
> ---
>
> Reply to this email directly or view it on GitHub:
> https://gist.github.com/1877934
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1877934
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how about something like: