First proposal

Here is a first proposal:

The first obvious benefit of this first approach is that we would have a clear model for items in our todo list. With that in place, it would become easy to come back and modify the data model in order to add new elements to it (for example, due date, assignee, and many others). This means that we would increase the clarity, readability, and maintainability of our code.

Also, since TodoItem objects would have a unique identifier, then it would be easy to manipulate them properly. In the first version of TodoIt, when we wanted to remove an item, we did so using only name, which simply removed any matching entry in the array. In our case, it wasn't a big issue, but for other use cases, you can imagine that it would not be ideal.

The TodoIt class would be the owner of the todo list and would expose methods to manipulate it: addItem and removeItem. In addition, it would also allow its clients to retrieve the full list of todo items through the getTodoList method, and to get a filtered version using an example object with the getFilteredTodoList method. With this defined, the application would expose a clear API to manipulate the todo list.

Moreover, thanks to the TodoIt class, we would be able to encapsulate all the logic related to the manipulation of the todo list.

Finally, the TodoListView would be the one responsible for handling all the DOM-related operations, such as retrieving the field values, and for updating the DOM to reflect the new content of the todo list.

Unfortunately, this first proposal has some major flaws. For instance, what is the entry point of the application? Is it TodoIt or TodoListView? Actually, with this first design, the view would be in charge of everything, which is far from ideal because it would have more responsibilities than it needs. The view should only ever be responsible for the user interface; it shouldn't control the flow of the application or its data model.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.185.147