A question on interfaces

S

Simon Harvey

Hi everyone,

I am in the process of making a small application and in the process of
designing and implementing it, I have come accross a sort of general design
related question.

I'm using the fairly typical approach of dividing the application into three
layers - UI - Business Logic - Data Access.

At the moment I am trying to figure out the best wya to let the logic layer
interact with the DataAccess layer. At the moment I have all communications
between the two layers going through a single class called
PersistenceManager. I have two questions:

1. Is it wise to have a single point of communication between two layers. It
seems like it might make serve the purpose of keeping the design relatively
simple. But is there any reason why a single communication channel might be
a bad idea?

(The most important question)
2. Given that the PersistenceManager class acts as *the* interface to the
data access layer - is this the sort of class that should have an interface
made for it? Then as I understand it, I would have the clients of the
PersistenceManager classes actually *talk* in terms of the interface? For
example I wouldnt put:

PersistenceManager pm = new PersistenceManager()

I would put this instead:

IPersistenceManager pm = controller.getPersistenceManager();

I hope the question is relatively clear. I'm just wondering if most people
would create an interface for this sort of situation. Would it be good
practice to do so, or a waste of time?

Many thanks all

Simon
 
F

Frank Oquendo

Simon said:
IPersistenceManager pm = controller.getPersistenceManager();

Interfaces are best used for communication between objects whose type is
not known. Given that your data layer is by all means a known, I don't
think an interface is necessary. However, the singleton idea you
demonstrated above is probably a good idea.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi Simon
1. Is it wise to have a single point of communication between two layers. It
seems like it might make serve the purpose of keeping the design relatively
simple. But is there any reason why a single communication channel might be
a bad idea?

No necesarilly.
(The most important question)
2. Given that the PersistenceManager class acts as *the* interface to the
data access layer - is this the sort of class that should have an interface
made for it? Then as I understand it, I would have the clients of the
PersistenceManager classes actually *talk* in terms of the interface? For
example I wouldnt put:

PersistenceManager pm = new PersistenceManager()

I would put this instead:

IPersistenceManager pm = controller.getPersistenceManager();

As Frank said an interface here is not of much use, you could use a
singleton pattern or even better a class with static methods.

Merry X-mas,
 

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