Re: EOFCommandments
Re: EOFCommandments
- Subject: Re: EOFCommandments
- From: David LeBer <email@hidden>
- Date: Wed, 31 Aug 2005 07:36:31 -0400
On 31-Aug-05, at 4:07 AM, Wolfram Stebel wrote:
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:
I don't see this as being an other hand...
It is following the "commandments".
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;
}
See, create a Customer and immediately insert it into an
editingContext - commandment fulfilled.
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?
So yes, it is perfectly safe and I've done it many times this way.
Factory methods are a nice way of minimizing your component code.
--
;david
--
David LeBer
Codeferous Software
site: http://www.codeferous.com
blog: http://david.codeferous.com
_______________________________________________
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