Avoiding cyclic header imports
Avoiding cyclic header imports
- Subject: Avoiding cyclic header imports
- From: Erik Stainsby <email@hidden>
- Date: Tue, 10 Jul 2012 17:01:53 -0700
I have two classes, and a model object - RSPlugin, RSExpression, and RSRule - which share the same data model.
I have thought to have the classes provide a method which can be used to initialize the RSRule object so:
RSRule * rule = [[RSRule alloc] init];
[rule loadFromPlugin: currentPlugin];
where -[RSRule loadFromPlugin:] copies the values to the rule. This requires however that RSRule #imports the RSPlugin header.
I also would like to maintain symmetry by having RSPlugin import the values of RSRule, for purposes of round-tripping to the UI (plugin reps the UI for a rule instance). Obviously, this would require RSPlugin to #import RSRule's header. Xcode doesn't like this one bit.
The same sort of reciprocal data-swapping interface would be wanted for the RSExpression side of the chain.
I imagine this is such a commonplace sort of relationship that there must be a standard approach (or perhaps several approaches) to solving it. My first stab at it was to try and provide the interfaces as categories but I ran into a similar issue with circular imports.
Anyone got a pointer to a Comp Sci 101 style description of how to avoid this? Thanks for your time.
~ Erik
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden