Tutorial on N-Tier-Architecture

its basically just separating out a project into layers that only handle their delegated element.

For example, you go through a UI layer (whether mvc or an api or whatever else, this is the front) into a business logic layer, where you put anything modifying/checking/etc data. After the business logic layer you go to a data access layer which handles the I/O, whether it be a text file or reaching out to a sql database or anything else.

So you have UI telling the BLL "Here, this is yours" and the BLL is like "Okay...i'm doing stuff with this, now I need to send or retrieve or change data in storage. Hey, Data layer, this is your job" and then the data layer is like "cool guy, thanks. Imma inserting/deleting/updating/querying your data and handing it back up now." Then the business layer is like "sweeeet. Yep, this looks like what I wanted. Hey UI, I've finished this stuff." The UI then serves back the appropriate response. This data is passed around in a model object from layer to layer.

The UI should reference the model and the business layer, the business layer should reference the model and the data layer, and the data layer should reference the model. With basic CRUD things, a lot of the time there really isn't much if any business logic, so it just becomes a place you instantiate the data layer and pass it along without doing anything else.

I'd also make sure that whenever you touch any kind of I/O you are prepared to handle failures, since that is an extremely likely place for it to happen since its depending on an external resource.

/r/learnprogramming Thread