Passing business objects through layers in a layered architecture

I am currently working on a project using a layered architecture, as described in the Application Architecture Guide 2.0 with 5 layers (DAL, BLL, Facade, Presentation Level, and General Level).
Here we have a business logic level consisting of business components and business objects (which are entities generated using O / R Mapper), we regularly need these entities at our presentation level to bind and present data to the user, so that we these objects bubbled up to presentation level through other layers.

Now the question is:
Is this the right approach? (As I know by definition, if we should share them, we should put them in the Common Layer so that we can use them in all layers). Shouldn't we move these objects to a common layer? or we should define something like data transfer objects (DTOs) and pass them through layers (which, of course, seems redundant).

Any clarification would be appreciated.

+4
source share
2 answers

A proper layered application typically uses DTOs to prevent falsification and distortion of business objects in accordance with the needs of other layers, among other reasons.

However, in very small applications, you can get rid of the burden of DTO mapping and ensure that business objects are fully consistent with the user interface. You can keep them in BLL, it is not dramatic if all layers have a link to it. This is actually not a very tiered application, since you crushed the architecture into one large layer.

Mark Seemann has an interesting blog post on this issue.

+3
source

Keep your business objects at the business level only. Initially, DTO may seem redundant, but as the project grows, you will begin to notice the differences between them: DTOs are much flatter, and serializable types and entities have much more complex relationships and power, they carry more application logic than DTOs.

DTOs are simple data, and for this reason they are suitable for transferring this data between layers. They do not have to be a direct representation of your entities, and for this reason they can improve compatibility when you need to change your BLL, but maintain service contracts.

The only exception may be the interaction of DAL and BLL, where the DAL will access objects directly. But even here, DTO could be used to absorb the effects of ORM.

+1
source

All Articles