Is there any place for OOP in redux?

前端 未结 3 764
耶瑟儿~
耶瑟儿~ 2021-02-05 06:14

I\'ve been using object-oriented programming practices for 25 years and trying to move toward functional programming for the last 5 years, but my mind always goes towards OOP wh

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-05 07:00

    This question is a bit opinion-based but let's concentrate on the core points.

    There is no contradiction between functional programming and OOP. You just need to use the same programming patterns. There is no problem to use classes (with inheritance) in functional programming, if you keep them immutable.

    To prove my point, the popular library Immutable.js that is used by many people to keep state in redux is composed from classes. And those classes have inheritance (e.g. OrderedSet extends Set).

    Also note that most React components are classes and they use inheritance, too (... extends React.Component).

提交回复
热议问题