Tower
Tower

Reputation: 102945

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.

Upvotes: 3

Views: 2518

Answers (1)

neuro
neuro

Reputation: 15210

Well in fact it is overwhelming. There is no simple answer or chosen design patterns. I will begin to apply the "separation of concern" design principle. One class/set of functions only do one thing. That will help to reduce the complexity. Then you can apply structural design patterns. To begin, you can just use delegation. In your case the decorator design 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

Upvotes: 7

Related Questions