Design pattern for filtering a collection of items?

前端 未结 6 949
既然无缘
既然无缘 2021-02-04 04:43

Imagine the typical type of application where you have a list of items with different properties. E.g. a tree-view with 100 items, each having a name, a rating

6条回答
  •  孤独总比滥情好
    2021-02-04 05:34

    I don't know about a design pattern for it, but you can look at some of the approaches that have been made for sorting, and it would be helpful if you explained some of them and why you didn't like them as an example.

    For example, LINQ has a nice way to do sorting, using the Expression trees.

    You can also look at sorting done in functional languages, where you can pass in the function to actually do the sorting, rather than hard-coding any particular sort.

    If you were working in something like javascript then the sort function could be created on the fly.

提交回复
热议问题