In a calendar app adopting a MVC
architecture, the Model
consists of objects representing the days of the week.
The View
consists of labels displaying the days as strings or integers, depending on the user interaction.
Therefore I need some logic in my app for the mapping from strings to integers, and viceversa. Is this logic, business logic or presentation logic?
As first thought, I decided to include this logic to the View, because the format in which the data is displayed is a View responsibility.
However a second thought came to me, when I realised the mapping describes how data is manipulated and transformed, therefore it should be included in the Model, and not in the View.
1 Answer 1
It's presentation logic. Think about the string you are converting it to. What language is it in?
Business logic is the same regardless of language. You just need to know the date.
-
Ok. One more question: let's say I want to compute how many days has been since the beginning of the month. Is that business logic instead?aneuryzm– aneuryzm2017年07月01日 16:14:55 +00:00Commented Jul 1, 2017 at 16:14
-
are you using it for presentation or is it part of the business logic?Ewan– Ewan2017年07月01日 16:17:41 +00:00Commented Jul 1, 2017 at 16:17
-
From your comment I deduce that it can be both depending where I use it?aneuryzm– aneuryzm2017年07月01日 16:20:08 +00:00Commented Jul 1, 2017 at 16:20
-
1yes, anything can potentially be anywhere. for example maybe you have a business rule which says the prices change depending on the first letter of the day of the week. in that case it would be language dependentEwan– Ewan2017年07月01日 16:23:07 +00:00Commented Jul 1, 2017 at 16:23