Encapsulate the use of cases in software

I usually write usage examples for all the software that I develop. For each use case, I usually write a controller that directs the stream (implements a use case).

I recently started developing web applications using Asp.net MVC. One of the best practices of Asp.net MVC is to keep very little logic in the controllers. I can't figure out how to change my design to reflect this.

Basically I want to encapsulate my use cases.

+3
source share
3 answers

Create a business component to encapsulate use cases. For example, if you have a vacation management system, you will have use cases such as applying for a vacation, approving a vacation request, rejecting a vacation request, etc. To do this, you can create a business component (class) called Leave Manager, using methods (functions / operations), for example, Apply, Approve, Reject, etc. These methods will encapsulate your use cases. These methods will cause your business entities and data warehouse classes to be entered and executed by use case.

class LeaveManager{
     int Apply(from, to);

     bool Approve(leaveApplicationId, approverId);

     bool Reject(leaveApplicationId, approverId);
}

Then you can use this business component in your controllers to fulfill a use case by supplying the necessary parameters.

+1
source

, - , , , .NET MVC. , , Ruby on Rails ( ).

, , - , .

+1

- , , URL- , . .

+1
source

Source: https://habr.com/ru/post/1728888/


All Articles