fantastic-five/project — pull request #23 by Ajedi32 (2013-11-19 01:39:24+00:00)
Title: Decouple Business Logic from Servlets

This merge request is pretty large and changes the structure of the project pretty drastically, so let me explain what's going on here.

Servlets are very difficult to test. They use complicated request and response objects that are difficult to duplicate in tests, they're slow (relatively speaking), and their methods don't provide output in a test-friendly manner. My solution here is to extract all business logic out of the servlets and into these `use_case` objects. Then, we can tests these `use_case` objects instead of trying to test the servlets.

So here's a quick overview of the new architecture:

````
edu.uwm.cs361.fantastic_five.training_tracker/
app/
entities/
use_cases/
requests/
responses/
services/
servlets/
tests/
````

All aspects of the application's business logic are now under the `app` package. This package currently includes entities and use cases.

Entities are basically the same stuff we've already been using (persistable data models).

Uses cases are what contains our application's business logic. Use cases are passed data via their corresponding request objects, and return data using a response object. These objects are basically just Structs (raw data objects). They don't contain any logic at all, just public data members.

Services are objects not related to our application's core business logic, but are needed to make the application work. Currently, this just contains a class that lets us obtain persistence manager objects.

Servlets are (obviously) our application's servlets. These shouldn't contain any business logic; they just delegate everything to use case objects, passing data via request objects and getting it back via response objects.

And tests contain all our unit and integration tests. That directory is pretty sparse right now; we'll need to add tests for all our use cases. Maybe later we'll also have full stack acceptance tests, like selenium. I'll see about those later.

I realize this adds a bit of complexity to our application, but I think overall the architecture is cleaner and still pretty straightforward. Plus, it makes everything much easier to test, which IMO is a big win. Anyway, that's about it; what do you guys think?