0

I have a simple REST application with a single controller. The application needs to fetch data from a Database, convert it to JSON and return this to the caller.

I need to decide what layers I should use. This is what I have so far:

Presentation layer: Contains the Controller which uses a Delegate that in turn calls a Service. The Delegate is part of the presentation layer.

Service layer: Contains the Service that has business logic to get the data/information that was requested by the caller. This is calling the DAO.

DAO layer: I actually only need to read from the Database (for now). So this contains the logic to read a Stream from the database and map that to a Domain object.

Domain layer: Contain model objects. Simple POJO's.

This is the first time I actually need to think about package layers, architecture etc. I have read a lot lately regarding these things and I am getting confused the more I read.

  1. Am I on the right track here? Does this make any sense? Keep in mind that this is a very simple Application right now.
  2. Do I even need the Delegate? Can't I just call the Service from the Controller?

    Any help is appreciated. Thanks.

1

I think it's largely correct, other than I don't understand at the moment what part your delegate plays. As such I would probably remove it if you don't see that it adds anything. You can always add this in later.

When faced with these issues, I try to keep some basic separation along the tracks of a well-known pattern e.g. MVC. My primary focus is to not expose implementation (e.g. DAO exposed directly to the presentation layer) and to provide composition and separation for ease of automated testing. If you've separated and composed such that you can test easily, that will translate into an easier path for enhancement going forwards, and you can always add complexity when you understand its necessity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.