MVP-iOS icon indicating copy to clipboard operation
MVP-iOS copied to clipboard

Presenter通过向View传model数据进行交互,难道不是View和Model产生了关系?

Open lichanghong opened this issue 7 years ago • 3 comments

Presenter通过向View传model数据进行交互,难道不是View和Model产生了关系?

lichanghong avatar Jan 09 '19 07:01 lichanghong

这个跟MVC的在C中设置View的Model有啥区别?如:userCell.configureWithUser(user)

lichanghong avatar Jan 09 '19 07:01 lichanghong

这个跟MVC的在C中设置View的Model有啥区别?如:userCell.configureWithUser(user)

我的认为是,不应该对cell传递user,而应该传cell对应的presenter。类似于 userCell.configureWithCellPresenter(cellPresenter)。然后cell的presenter中包含了数据的格式化等逻辑。不应该直接暴露user给cell。比如要获取一个name属性。 cell.nameLabel = [cellPresenter getNameStr]; just like this

fuCking-Life avatar Jan 24 '19 00:01 fuCking-Life

我认为作者的写法还没做到MVC的要求,让V和M达成解耦。

MVP除了要隔离V和M,还提出了让P承担展示逻辑、让P具备可测性、P不能依赖UIKit。记住这几条就不会搞混了。

建议想正确理解的可以看下这个项目,以及这篇文章

miyazaki2048 avatar Apr 20 '20 01:04 miyazaki2048