business-logic

Repository, Service or Domain object - where does logic belong?

Deadly 提交于 2021-01-27 03:55:57
问题 Take this simple, contrived example: UserRepository.GetAllUsers(); UserRepository.GetUserById(); Inevitably, I will have more complex "queries", such as: //returns users where active=true, deleted=false, and confirmed = true GetActiveUsers(); I'm having trouble determining where the responsibility of the repository ends. GetActiveUsers() represents a simple "query". Does it belong in the repository ? How about something that involves a bit of logic, such as: //activate the user, set the

Repository, Service or Domain object - where does logic belong?

喜欢而已 提交于 2021-01-27 03:55:20
问题 Take this simple, contrived example: UserRepository.GetAllUsers(); UserRepository.GetUserById(); Inevitably, I will have more complex "queries", such as: //returns users where active=true, deleted=false, and confirmed = true GetActiveUsers(); I'm having trouble determining where the responsibility of the repository ends. GetActiveUsers() represents a simple "query". Does it belong in the repository ? How about something that involves a bit of logic, such as: //activate the user, set the

Repository, Service or Domain object - where does logic belong?

久未见 提交于 2021-01-27 03:53:56
问题 Take this simple, contrived example: UserRepository.GetAllUsers(); UserRepository.GetUserById(); Inevitably, I will have more complex "queries", such as: //returns users where active=true, deleted=false, and confirmed = true GetActiveUsers(); I'm having trouble determining where the responsibility of the repository ends. GetActiveUsers() represents a simple "query". Does it belong in the repository ? How about something that involves a bit of logic, such as: //activate the user, set the

Clean architecture - where to put input validation logic?

梦想与她 提交于 2020-07-05 11:43:01
问题 Perhaps in the app I have a feature allowing users to send feedback using a form with some validation logic: name can be empty feedback message should be at least 5 characters Where would you put these validation logic, either in domain layer as business logic or in presentation layer as UI logic? These logic are applied for all applications (android, iOS, web). Please note that we already had server side validation. 回答1: I think many developers do that in Presentation layer, specifically in

Clean architecture - where to put input validation logic?

一曲冷凌霜 提交于 2020-07-05 11:41:05
问题 Perhaps in the app I have a feature allowing users to send feedback using a form with some validation logic: name can be empty feedback message should be at least 5 characters Where would you put these validation logic, either in domain layer as business logic or in presentation layer as UI logic? These logic are applied for all applications (android, iOS, web). Please note that we already had server side validation. 回答1: I think many developers do that in Presentation layer, specifically in

How to return an error message from the Model?

柔情痞子 提交于 2020-01-15 11:45:30
问题 In suppliment to this question, if business logic should be in the model, how do I return an error message from the model? def save(self, *args, **kwargs): if <some condition>: #return some error message to the view or template 回答1: Pastylegs is correct, but you shouldn't be doing that sort of logic in the save method. Django has a built-in system for validating model instances before saving - you should use this, and raise ValidationError where necessary. 回答2: Raising an exception is the way

How to handle views in a multilayer-application

被刻印的时光 ゝ 提交于 2020-01-07 06:27:51
问题 I'm working on a project which has basically three layers: Presentation, business and data. Each layer is on a different project and all layers use DTO's defined in another project. business layer and data layer return DTO's or Lists of DTOs when querying the database. So far so good, but now we have to query views and those views of course do not match an existant DTO. What we have done until now is just create a special DTO, business- and data-layer classes so they were treated like normal

Adding code to Entity Framework 4 generated POCOs

江枫思渺然 提交于 2020-01-05 07:07:28
问题 Starting from an EF 4 entity diagram and using T4 templates one can create POCO classes that can be used inside the Domain Model. The generated code looks like this: public partial class Product { public virtual int Id { get; set; } public virtual string Name { get; set; } //and so on } Is there any elegant approach to add my own code for implementing the properties? for example, the Name setter I would like to be implemented by lowering all the characters. I would like that my code resist to

Business logic in Enums?

浪尽此生 提交于 2020-01-02 02:35:06
问题 Is it considered good practice to put any type of business logic in Enums? Not really intense logic, but more of like convenience utility methods. For example: public enum OrderStatus { OPEN, OPEN_WITH_RESTRICTIONS, OPEN_TEMPORARY, CLOSED; public static boolean isOpenStatus(OrderStatus sts) { return sts == OPEN || sts == OPEN_WITH_RESTRICTIONS || sts == OPEN_TEMPORARY; } } 回答1: IMHO, this enables you to put relevant information right where it's likely to be used and searched for. There's no

N-layered database application without using an ORM, how does the UI specify what it needs of data to display?

百般思念 提交于 2020-01-01 05:20:07
问题 I'm looking for pointers and information here, I'll make this CW since I suspect it has no single one correct answer. This is for C#, hence I'll make some references to Linq below. I also apologize for the long post. Let me summarize the question here, and then the full question follows. Summary: In a UI/BLL/DAL/DB 4-layered application, how can changes to the user interface, to show more columns (say in a grid), avoid leaking through the business logic layer and into the data access layer,