A design pattern for filtering a custom data structure

I have been given the following data structure and now I need to apply the rules to filter this bucket. An example would be to filter out all items that are listed by user bob and by credit card payment method. The rule varies from case to case.

All of these below are complex types in my request and response with a concrete implementation without an interface implementation.

What would be the best design pattern to separate my data structure and the rules that apply over it. Will the decorator pattern help? Your suggestions are appreciated.

   public class PaymentType {
        private String paymentType;

    public class Items {
        private Integer itemId;
        private String category;
        private List<PaymentType> paymentOptions;

    public class Group {
        private Integer sellerId;
        private List<Items> itemList;

    public class Cart {
        private Integer cardId;
        private List<Group> group;



source to share

1 answer

  • If you need to perform several different operations for each PaymentType, you can try STATE PATTERN and delegate your request.

  • The DECORATOR PATTERN is used to add additional responsibility at runtime, so I didn't really find such a scenario, perhaps I'm missing somewhere.

Other elements, the group can be divided into two parts and there is a DECORATOR option.

If the cardinality is corrected, then the COMMAND PATTERN can be used, and the UNDO script will even help to dump / accept an element to / from CART



All Articles