Composition vs Inheritance in MVP

后端 未结 5 1292
挽巷
挽巷 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:22

    Is it really better for my case to use composition over inheritance? Why?

    Yes. Because composition is more reliable, more secure, more maintainable, more discoverable, more documentable, and more comprehensible in larger apps. IMHO. :)

    Does using composition "break" MVP?

    Yes. It breaks the kind of simple MVP you're doing now. Composition lets you choose how to couple your code, and this is very good for larger apps. It does use more code because you have to become specific about how you're coupling.

    It is very reasonable for a simple app to grow, and to become a good candidate for a transition from simple MVP inheritance to more sophisticated composition. This is a decoupling step that enables recoupling in new ways.

    This is similar to how many simple web apps are transitioning to become front/back API-driven apps. This is essentially a decoupling of the front-end user views from the back-end storage models.

提交回复
热议问题