Layering struts application

G

Grzegorz Stasica

Hi',

Let's make 3 layer: presentation,business object and DAO. Having in mind
principle no layer should know how the other works I've question
regarding DAO layer. Let's assume I've a CustomerDAO object which
resposibility is limited to talking with underlying DB. My question or
I'd say ignorance is how to get a connection in DB layer since all
information about parameters are stored in application context
(struts-config.xml). Surely I can get DataSource object from JNDI but
whouldn't it be breaking a base principle(the above solution I've seen
on apache.org web site).

I've somebody will explain it to me :)
Please don't slam me to much :)
 
S

SPG

Hi,

It would be the responsibility of the business layer to obtain the
'application' DataSource.
The data layer would simply accept a DataSource in its constructor.

This way you would not be breaking any layer separation rules. The business
layer knows it has to call the data layer some how. It also now knows it is
responsible for obtaining the DataSource and sending it to the Data Access
Layer.

The Data Access Layer will not care what type of DataSource it gets, as
DataSource is an interface (or abstract class, cannot remember right now),
but knows how to act upon the DataSource.

I hope this helps you in the right direction..

Steve
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top