Circular Dependency - OO Model

Circular Dependency - OO Model

Old forum URL: forums.lhotka.net/forums/t/2532.aspx


somayajulu posted on Friday, March 16, 2007

Hi there,

I'm trying to build a .Net application following a couple of considerations in the architecture:
1. There shall be User Interface Layer, Business Logic Layer and Data Access Layer
2. All the three layers shall be in separate projects

I would like to achieve the following out of this layered architecture:
1. User Interface shall request for an object to the Business Layer
2. Business Layer shall send an empty Business Object to the Data Access Layer
3. Data Access Layer shall populate the Business Object and send it back to the Business Layer
4. Business Layer shall send the populated Business Object back to the User Interface.

The problem:
I have set a reference in the Business Layer to the Data Access Layer. Now for the Data Access Layer to recognize the Business Object, I have to set a reference in the Data Access Layer to the Business Layer. This will throw a circular dependency error.

Is there a workaround for this issue which follows Object Oriented Model?

Regards,
Som.

ajj3085 replied on Friday, March 16, 2007

Well, this is why Csla objects have the DataPortal_XYZ methods.  If you check out Rocky's book, chapters 1 & 2 of the Second Edition, he comes to exactly this same conclusion when discussin possible archtechtures., and the compromise is the DataPortal methods and the BO just knows how to use the DAL to get or save its data.

malloc1024 replied on Friday, March 16, 2007

If you want to separate the db code from the business object, you might want to look into the separated interface http://www.martinfowler.com/eaaCatalog/separatedInterface.html .  It can be used to solve the circular reference problem.  Another option would be to use DTOs.

Brian Criswell replied on Friday, March 16, 2007

You may also want to check out this J2EE example.  http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html

somayajulu replied on Saturday, March 17, 2007

Thanks for the usefull ideas and links!
I'll have a look at them.

Regards,
Som.

Copyright (c) Marimer LLC