1

In a good layered design of an application, where would logic that generates an order number for an order entity sit?

The logic will need to lookup and increment either a sequence or a table with these ranges.

For example, if i have a service called CreateOrder in OrderService, would this logic sit in another method in that service?

Or is it a static method somewhere?

1

It depends. If the only way for an application to create an order is to go through the same business layer then you can have it at the business layer. If you have app1, app2 and they have their own business layers but they share the same data access layer, then put it in the data access layer.

The idea is to put it in a location where you will not have to write it again and again for different applications and if the logic for generating the order number was to change due to a business rule, it should only need to be changed in one place.

  • I can't see why this would exist in a data access layer.. regardless of the amount of applications. I'm more leaning towards this being part of the OrderService.. or perhaps its own service, such as DocumentNumberService perhaps where you pass in the document type (Order/Receipt etc) and it returns an order number for you to use? – Lock Feb 22 '17 at 1:31
  • If the dal is used by multiple apps and they do not share the same business layer, then it should be in the dal. Otherwise, code will be repeated. – CodingYoshi Feb 22 '17 at 4:35
  • But why is this considered DAL logic? To me, this is on the fence between business logic and application logic. – Lock Feb 22 '17 at 4:36
  • Read my last comment please and tell me where would you put it in that case? – CodingYoshi Feb 22 '17 at 13:34
  • Your last comment suggests putting it in the DAL.. but I'm saying I don't see how this logic has anything to do with data access? – Lock Feb 22 '17 at 23:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.