Composition vs Inheritance in MVP

后端 未结 5 1331
挽巷
挽巷 2020-12-29 05:43

I\'m using MVP pattern to develop a large scale application. While working in the development I have come up with the question whether if composition or inheritance should b

5条回答
  •  情深已故
    2020-12-29 06:29

    when the forms are different they handle common inputs (A and B).

    this means Foo presenter is conceptually different from Bar presenter and just happen to share some common input so they should not be related by inheritance. extract the code that handles common inputs into utility class and reuse that in both Foo presenter and Bar presenter.

    in case concept of Foo changes, it will not affect Bar (and the other way around: if concept of Bar cannot change without changing concept of Foo too, then it is "is A" relationship and inheritance could be used indeed)

    when in doubt, always prefer composition

提交回复
热议问题