yad4u Setting a default value — presentation logic or business logic?


Setting a default value — presentation logic or business logic?



I was wondering if setting a default value for a SelectList is considered to be presentation logic or business logic? For example, if a requirement is that an Employee cannot be saved without a Location, but 99% of the time the location that would be selected is a particular item -- say Atlanta. Because of this, the location SelectList should be defaulted to Atlanta when ever a entry screen for a new employee is displayed. Should I be defaulting the location in the model or in the view-model? One thing I realized is that the unit tests become awkward because in both cases, I'd be forced to test against a location that will always be present in production but I cannot create a unit test with my own test data unless "Atlanta" was in the set of locations being used in the test. I'd be greatful if you have any thoughts on this as well.




would i need antixss for report printing

1:



using MultiSelectList in ASP.NET MVC
As with many such questions (subjective) the answer is: "It depends.".
ASP.NET MVC Form Submit with Link instead of Button
If the "default value" is a business default (say, a default location of a business location, or a default number of units on an order or somesuch) that's probably business tier.


Using jquery to generate a Slug from Title (on lost focus)
That appears to be correct for your specific situation here..
Is it possible to load content dynamically through ajax (instead of upfront) in simile timeline
However, if the "default value" of your list is simply because you need some value to be the default, and you're just going to choose index 0, or just going to choose based on the user's location or system settings, I would think those would be presentation tier issues..
Error when Saving into SQL Server


ASP.NET MVC iframe load


ASP.NET ActionFilters and inheritance

2:


Because of this, the location SelectList should be defaulted to Location5 when ever a entry screen for a new employee is displayed.

Should I be defaulting the location in the model or in the view-model?.
It's business logic in your example, but that won't stop you from having your cake and eating it too in this instance.

The model can specify a default value; the view then initializes itself with this default value.. In general, whether or not something is "business logic" or "presentation logic" depends on whether it concerns the domain or not.

For instance, setting the earliest year in a date drop-down to, say, 1900 is probably a presentation concern.

But it could also be a business concern, if the system isn't designed to accept dates earlier than 1900..
One thing I realized is that the unit tests become awkward because in both cases, I'd be forced to test against a location that will always be present in production but I cannot create a unit test with my own test data unless "Atlanta" was in the set of locations being used in the test.

I'd be greatful if you have any thoughts on this as well..
With the strategy I mentioned above, unit-testing is easy.

Simply verify that:.
  • the model provides a default value
  • the view accepts this default value
  • the view initializes itself to this default value
  • the view has the appropriate behavior whether or not the model supplies that value


3:


I would have thought default values are business logic.. For example, if the company relocates the default location is no longer "Altanta" or "London", but "New York" or "Nottingham"..


4:


If you were really concerned about preserving the boundaries of business rules and the presentation layer, you could provide the default value through the business logic and your presentation layer could use that default value to initialize controls..



59 out of 100 based on 24 user ratings 799 reviews