• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convenience functions in model classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convenience functions in model classes


  • Subject: Re: Convenience functions in model classes
  • From: Chuck Hill <email@hidden>
  • Date: Fri, 11 Apr 2008 16:42:02 -0700

I will defer answers to your questions to a reply to Art's message.


On Apr 10, 2008, at 6:46 PM, Jeff Schmitz wrote:
Continuing on with my EO indoctrination, I think I understand the concepts ok, but when it comes to fleshing the concepts out into actual code I'm still struggling. I was hoping before I get too along down a wrong road, one of you experts might take a look at a small function I've added to one of my EO Objects. This function basically traverses down several EO Relationships and loops through an array of EO Objects at the end, looking at the state of an attribute (selectedItem) in each one in order to determine a result to return.

public class Pool extends _Pool {
	private static Logger log = Logger.getLogger(Pool.class);

// Question 1: Does a function like this really belong down in my EO class.
// There's something about doing the actual Fetches in this class that rubs
// me the wrong way, however I don't want to put it in my Component classes
// either since there may be multiple components that would like this
// functionality.
// Question 2: If it does belong down in my EO class, does it belong in THIS EO class,
// which represents the "top of the chain"
// in a chain of relationships that are traversed to get the actual data to
// return? Or should I just fetch the entry from here first and move this function down
// into the Entry EO Class?


	// Question 3: Does this need to be static?
	public boolean hasResults(EOEditingContext ec, String poolName,
			String entryName) {

	   EOQualifier poolQual = Pool.NAME.eq(poolName);
  	   EOQualifier entryQual = Entry.NAME.eq(entryName);
	   boolean results = false;

// Question 4: Is exception handling always the best way to handle the
// no results case? OR should it be saved for cases where not finding
// what you're looking for indicates there is something really wrong with
// your app?
try {
Entry entry = Pool.fetchRequiredPool(ec, poolQual).entries(
entryQual).objectAtIndex(0);

That seems like an exceedingly odd way to get a single entry on a single Pool. Does the code that calls this not know the Pool? How does it get the Pool and Entry names?


Even if you only have the names,

EOQualifier entryQual = ERXQ.and(Entry.NAME.eq(entryName), ERXQ.equals(ERXQ.keyPath(Entry.POOLKEY, Pool.NAMEKEY), poolName));
Entry entry = Entry.fetchRequiredEntry(ec, entryQual);


Seems like a more direct way to do it. And it handles the exception for you so no need for a try ... catch.

NOTE: I don't use the key stuff from Wonder yet, so I am just guessing at Entry.POOLKEY for the name of the property.



// Check first round to see if any actuals have been set. for (int i = 0; i < 4; i++) { for (int j = 0; j < 7; j++) {

// This call is to the Mike Schrag approved "game" function from
// my previous message (see below).
if (entry.game(i, j).selectedItem() != 2) {

// If selectedItem isn't 2 for any game, results have been posted.
results = true;

//Break out of loops
i = 4;
j = 7;
}
}
}

How about boolean posted = false;

	   // Check first round to see if any actuals have been set.
	   for (int i = 0; i < 4 && ! posted; i++) {
		for (int j = 0; j < 7 ! posted; j++) {

// This call is to the Mike Schrag approved "game" function from
// my previous message (see below).
if (entry.game(i, j).selectedItem() != 2) {

// If selectedItem isn't 2 for any game, results have been posted.
posted = true;
}
}
}


No nasty hacking of for loop variables.

And this is no longer needed.



// Question 5: Do I need any other exception handling? } catch (NoSuchElementException e) { results = false; }

 	 return results;

	}
}
On Apr 4, 2008, at 11:50 PM, Jeff Schmitz wrote:
Hello

As I get rolling down the EO highway, I find myself wanting to put convenience functions in the model classes that are generated by the EOGenerator (yes, I'm using the generation gap classes for this). e.g. to more closely mimic indexing a two dimensional array like the "old" way I used to do things, I create the following to retrieve a Game object from in from a model class that contains a one to many relationship to Game objects:

public Game game(int group, int gameIndex) {
EOQualifier gameQual = Game.GROUP.eq(group).and(Game.GAMEINDEX.eq(gameIndex));
Game game = this.games(gameQual).objectAtIndex(0);
return game;
}


Is this a good thing? Just hoping to get some feedback before I go too far down this road.

Thanks,
Jeff


_______________________________________________ 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

_______________________________________________ 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

--

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects






_______________________________________________
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


  • Follow-Ups:
    • Re: Convenience functions in model classes
      • From: Jeff Schmitz <email@hidden>
References: 
 >Convenience functions in model classes (From: Jeff Schmitz <email@hidden>)
 >Re: Convenience functions in model classes (From: Jeff Schmitz <email@hidden>)

  • Prev by Date: Re: rowDiffsForAttributes _dbSnapshot and _newRow missing attributes
  • Next by Date: Re: Convenience functions in model classes
  • Previous by thread: Re: Convenience functions in model classes
  • Next by thread: Re: Convenience functions in model classes
  • Index(es):
    • Date
    • Thread