EOFCommandments
EOFCommandments
- Subject: EOFCommandments
- From: Wolfram Stebel <email@hidden>
- Date: Wed, 31 Aug 2005 10:07:44 +0200
Am 29.08.2005 18:53 Uhr schrieb "Chuck Hill" unter
<email@hidden>:
Hi List,
>From another thread:
> Two explanations come to mind:
> 1. You are saving the wrong editing context
> 2. Your bad code has hosed EOF. Does anything here look familiar?
> http://www.wodev.spearway.com/cgi-bin/WebObjects/WODev.woa/wa/Main?
> wikiPage=EOFCommandments
There is the EOFCommandment:
2. Don't do anything to an EO before inserting it into an editing context.
Always insert EOs into ECs immediately
On the other hand:
There is a document "WebObjects Naming Conventions and Design Patterns" by
email@hidden
whom i followed in recommendations for object creation:
4
Static ³Constructor² Methods: Each custom class will have a static (factory)
³constructor² method which accepts an EOEditingContext and returns an EO of
its class type. The static ³constructor² will also insert the newly created
EO into the passed in editing context and hook up all its appropriate
relationships. Each class may have multiple static methods which handle
different cases when creating new EOs, but each class will at least have the
equivalent of a default static method which is intuitively named, i.e. a
Customer.java EO will have the following method:
public static Customer newCustomer(EOEditingContext editingContext) {
Customer customer = new Customer();
editingContext.insetObject(customer);
return customer;
}
The job of this method is to create a new EO, insert it in the editing
context and hook up its appropriate relationships. The relationship hookups
may be done in awakeFromInsertion().
Other methods will build on this default method such as:
public static Customer newCustomerWithShoppingCart(
EOEditingContext editingContext, ShoppingCart shoppingCart, Sting
relationshipName) {
Customer customer = Customer.newCustomer(editingContext);
customer.addObjectToBothSidesOfRelationshipWithKey(shoppingCart,
relationshipName);
.
.
.
return customer;
}
Is this a save way to create EO's, especially to second one?
Wolfram
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden