Search code examples
gwtfor-loopmvp

What are the guidelines between rendering logic and business logic in MVP?


I was working on a GWT application and was told that a for loop constituted "business logic" and shouldn't be in the implementation class of the view for MVP. So as a habit I never use a for loop in my viewImplementation class, but put the loop in the Presenter (Activity) and call a method in the viewImplementation class to do each single iteration task of the loop.

I understand that the Presenters don't contain widgets and have the business logic. Conversely the viewImplementation class is where you have the widgets and keep the rendering logic, but is that too strict a guideline to classify a for loop as business logic?

Are there some guidelines for what classifies as rendering logic versus business logic for MVP using GWT?


Solution

  • I disagree with the statement "for loops constitute business logic". It is a syntactical construct not business logic. If he is making that statement then it follows (IMO) that you should avoid "If statements" as well. How practical and/or viable would that be!?

    The business logic is what you place inside the looping construct, not the construct itself. It all really depends on what you are logic you are placing within the loop that would be the determining factor here.

    EDIT

    One Example I could think of demonstrates how you would find a for loop in the View whereas according to the "for loop" rule it should only be placed in the Model.

    Imagine you want to make a Toolbar with the letters A-Z on it that a user could click to filter search results.

    A view is responsible for how things should be displayed to the user. For this reason I would argue using the following for loop to generate the toolbar in the View is the most appropriate approach.

    Pseudo Code

    Let TB <- Toolbar control
    for letter = 65 - 90 (A - Z)
    begin
          let item <- Toolbar Item
          set item's text to letter
          add item to TB
    end
    

    This seems to debunk the statement that for loops always constitute business logic and therefore, must be placed within a Model.