How to choose appropriate design pattern?

Which design pattern to choose

  • So I have ended up in a situation with a project I'm part of that has two types of lists (at the moment, at least): booking and shift list. Both lists are made so that we have a List object containing logic for both of them, and a separate Shift and Booking list objects for individual features. The List object is starting to be overwhelming. It has pagination, editor capabilities, selection and double click to open popups, mouse hover popups as well as filtering and paging. I would like to refactor the code to something more maintenable and perhaps into smaller units I suppose. What design patterns should I be thinking about here? If it matters, the List object contains over 3k lines of OO JavaScript code.

  • Answer:

    Well in fact it is overwhelming. There is no simple answer or chosen design patterns. I will begin to apply the "http://en.wikipedia.org/wiki/Separation_of_concerns" design principle. One class/set of functions only do one thing. That will help to reduce the complexity. Then you can apply http://en.wikipedia.org/wiki/Structural_pattern. To begin, you can just use delegation. In your case the http://en.wikipedia.org/wiki/Decorator_pattern can fit as you can "decorate" the basic list with functionalities depending of the usage ... Before thinking DP, think separation of concern to divide your code in small understandable parts. Then use some DP to link them all. Good luck ! my2c

Tower at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.