Coder Social home page Coder Social logo

Comments (1)

wenmingvs avatar wenmingvs commented on August 19, 2024 1
  1. 其实最初的版本,我就是多个TitleBar对应一个XML文件的,不同的Fragment使用一个XML文件,然后在相应的fragment中用代码对TitleBar里面的TextView做文本调整。但是到后面,TitleBar的功能就不这么简单了,比如首页的TitleBar就有个小箭头图标,发现页的TitleBar是一个搜索栏等等,这样,我还需要在代码里面做各种隐藏和显示操作,这样会让代码非常混乱,也很难后期维护。所以我打算每个fragment对应的TtileBar,如果后期TitleBar需要增加新的功能样式,我也可以方便扩展。
  2. 为什么采用MVP,如果你自己负责过一个非常完整的App项目,我想你就能明白架构对于程序设计的重要性。我最初设计的版本并没有使用MVP,导致了在fragment中不仅仅需要做更新各种UI部件,还需要做数据的网络请求,请求回来的数据我还要进行相应的二重处理等等。不仅仅在这个fragment中我需要做这些操作,我还需要在别的fragment中也需要重复做这些操作,这样代码就会冗余,而且会难以后期维护,我有一段时间写到后面完全不想再写,觉得非常烦,后来下定决定重构全部代码,才有写下去的动力。

你提到类爆炸这个点,我觉得其实还好,并没有到爆炸那么恐怖,只是把若干的功能都分离成更小的单元而已,MVP导致类的增多,其实大部分是接口类的增多,通过继承接口,我们后期做各种扩展,而不会影响到之前的代码方案,这也是MVP的好处。这也符合『对修改封闭,对扩展开发』的设计原则。

希望我的回答能解决你的困惑!

from weibo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.