Factory pattern

A

Andy

Hi all,

I'm developing n-tier applications and I'd like some advice.

I have my data layer, business layer, and application layers.

The data layer uses a method similar to the one described here:
http://www.codeproject.com/cs/database/dal1.asp.

Business objects encapsulate the data access objects, and know which DA
object properties map to the Business object properties.. but if the DA
objects change, i'll also have to modify the business layer...
something i'd like to avoid.

So I was thinking of implementing a Factory pattern, where the factory
knows which DOs to use to build the appropriate BOs, but I'm not sure
if this is appropriate (or if there's an even better way).

I'm also trying to figure out where the Factory pattern would fit, if
thats the way to go. Would the apps, using static methods off of
Business objects talk to the business objects that way, or would it
talk to the factories? I'm leaning toward the former.. the Business
layer static methods call the appropriate factory to create the
objects.

Comments?

Thanks
Andy
 
J

Jon Skeet [C# MVP]

Andy said:
I'm developing n-tier applications and I'd like some advice.

I have my data layer, business layer, and application layers.

The data layer uses a method similar to the one described here:
http://www.codeproject.com/cs/database/dal1.asp.

Business objects encapsulate the data access objects, and know which DA
object properties map to the Business object properties.. but if the DA
objects change, i'll also have to modify the business layer...
something i'd like to avoid.

So I was thinking of implementing a Factory pattern, where the factory
knows which DOs to use to build the appropriate BOs, but I'm not sure
if this is appropriate (or if there's an even better way).

Have you looked at Spring.NET? I'm currently using Spring in a Java
application, and it's wonderful not to set up any wiring myself...

http://www.springframework.net

(I confess I haven't used the .NET version myself yet, but I suspect
the bean configuring bit is pretty stable.)
 
A

Andy

Jon,
From what I've read so far about it, it provides away to setup config
files that detail how data objects map to business objects. Is that
correct?

Certainly sounds interesting, but isn't this just moving the plumbing
from code to a config file?

Oh, I'll assume that the factory pattern is the way you recommend going
(since Spring is a factory framework, i think)

Andy
 
J

Jon Skeet [C# MVP]

Andy said:
From what I've read so far about it, it provides away to setup config
files that detail how data objects map to business objects. Is that
correct?

Well, it sets up general constructor parameters and properties; any
collaborators etc. It doesn't have to be data objects to business
objects.
Certainly sounds interesting, but isn't this just moving the plumbing
from code to a config file?

Absolutely - but IMO that's a major advantage.
Oh, I'll assume that the factory pattern is the way you recommend going
(since Spring is a factory framework, i think)

Well, it all depends on how you set things up - it's very flexible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top