The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Design of Entity classes

I'm curious as to what people feel is the best way to design entity classes.  I'm working on a new project where I basically get to start from scratch and I'm re-evaluating some of my old designs.

Joel's technique used in CityDesk is here:

http://www.joelonsoftware.com/articles/CityDeskEntityClasses.html

My entity classes are very similar to Joel's except mine do not represent the set of entities.  I use a seperate class to represent any set of entities and the MoveNext() method of that class returns a specific filled entity.

Pseudocode Example:
// Resultset is raw database resultset
Articles = new EntitySet(new Article(), Resultset)
while (Article = Articles.MoveNext()) {
  Article.Publish();
}

The platform for this code is PHP4 -- which is weak-typed so you can do all kinds of nifty things like this.  This next project will be in PHP5, which is more Java-like but still weak-typed.

I also have the ability to load foreign-key related objects.  For example:

Article.FetchEntity('Author');
print Article.Author.Name;

The article contains enough information to load a "User" entity with the proper id (might be "AuthorID").  In PHP5 this could be completely automated with property get/set operations.

It also possible for queries to do the join of author for the entire set of articles.  So in a loop, you wouldn't need to query the author for each entity.

I'm really curious as to what other people consider to be good design when it comes to entity classes.

For example, should the Load() method instead be a static function which returns a loaded entity?  In that way, entities could more easily be cached and/or loading the same entity by id return the same instance of that entity.

Discuss!
Almost Anonymous Send private email
Monday, November 29, 2004
 
 
Martin Fowler's Patterns of Enterprise Application Architecture contains more approaches to this problem than the mind can comfortably comprehend.

Start from there and Google outward. There's a lot of fun discussion going on in the Domain Driven Design community (talk to them about your Article.Author.Name example and lazy loading, if you like).

Have fun! :)
Thom Lawrence Send private email
Monday, November 29, 2004
 
 
I've googled..  as you said, too much information.  I'm just hoping to get some ideas (or a general consensus) from other JOSers.
Almost Anonymous Send private email
Monday, November 29, 2004
 
 
I'll second Fowler's book.  I've read through most of it and have seen many of the patterns in my own code even before I knew what they were...

He also has a refactoring book out...
KC Send private email
Monday, November 29, 2004
 
 
You may find the book Domain Driven Design interesting.  It summarises the author's view of best practice regarding entity objects and related classes.

I also found this page interesting, on the design of entity classes: http://weblogs.asp.net/fbouma/archive/2004/10/09/240225.aspx
John Rusk Send private email
Tuesday, November 30, 2004
 
 
"Summarises" might not be the right word, it's a long book!
John Rusk Send private email
Tuesday, November 30, 2004
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz