Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Non-trivial module to module communication #8

Open
frankradocaj opened this issue Oct 14, 2014 · 5 comments
Open

[Question] Non-trivial module to module communication #8

frankradocaj opened this issue Oct 14, 2014 · 5 comments

Comments

@frankradocaj
Copy link

Even though this project seems to be abandonware, there aren't any better forums for discussing VIPER, so I hope there's someone actually implementing it IRL. (i'm gonna ask on StackOverflow as well).

Every example of VIPER I have found only provides a contrived example of communicating from module to module. The TODO app opens a blank Add screen. No information is needed from the previous (list) screen. That's the most simple (and contrived) example possible. But in reality there are lots of situations where you need to pass info from screen to screen.

For example, lets say we wanted to extend the TODO app to allow editing of todo items. In order to edit, you need to pass some info to the edit screen (module). Because communication happens between modules via wireframes, would I modify the VTDListWireframe so that the VTDListPresenter can call something like this:

// I'm passing the todo string here which will be used by the edit module to load the todo item for presenting on the edit screen
- (void)presentEditInterfaceWithToDo:(NSString*)todo
{
    [self.editWireframe presentEditInterfaceFromViewController:self.listViewController withTodo:todo];
}

Notice how my wireframe is now taking todo string. Is this in keeping with the VIPER pattern, or am I violating the boundaries between presenter and wireframe? Is there another way I should be communicating this to the next wireframe?

@sebastianwr
Copy link

I talked about some people about this and at some point you need to have a connection between the layers. Either by soft reference (ID of the object to be edited) or a dedicated "transition" class between two modules that receives/transforms an object.

Either way this architecture requires an interactor to pass enough data so that a unique object can be retrieved later on or the interactor passes a plain object that is a 1:1 copy of the database entity so that you can reuse it for the other module.

In my example app, I am just copying the database entity basically and the only transformation happens in the presenter from Model to View model. The presenter could save a map (i.e. Dictionary) that maps the model with the view model.

Now you can do the following: ViewController says to the Presenter: "This ViewModel was selected, please do something". Presenter gets the corresponding "real" model and passes it on to the wireframe and so on.

Anyway, interesting topic and I don't think there is one bullet-proof solution for this problem. Hope that helps!

P.S. I'm really glad about this architecture design but it's a shame that there is no response from the authors in such a long time. :(

@frankradocaj
Copy link
Author

Thanks @sebastianwr.

Either by soft reference (ID of the object to be edited) or a dedicated "transition" class between two modules that receives/transforms an object.

I like the idea of a dedicated transition object (or Data Transfer Objects - DTOs as we tend to call them in C#) by reference. I agree there isn't a prefect solution; I guess that is why there are so many implementations of the MV* pattern.

P.S. I'm really glad about this architecture design

Yes, this is by far the best architecture design I have found. The lack of discussion about this reflects my experience of iOS development - the majority of iOS devs don't use patterns, just monumental ViewControllers and singletons. Urgh.

@sebastianwr
Copy link

I think what we will use in our next private project is a mixture of a massive view controller and the VIPER architecture. The VC will not be doing too much work but gets data passed or asks other classes for what to do next. Decoupling of classes and having a single responsibility (i.e. "control your own view") is the main goal. So I'd say whatever you do to achieve decoupling will help the overall software design.

@xiaoxiaocainiao
Copy link

how about viper nesting?
for example, 'NameTableA' is a tableviewcontroller, 'NameTableB' is another tableviewcontroller, their are totally different tableview, now , for same reason, i have a listview containes the both tableviewcontroller, 'NameTableA' at up, 'NameTableB' at down.
both 'NameTableA' and 'NameTableB' at down use Viper structure, now what should i do?? put a viper into a view? or...put view in view ,put presenter in presenter,
confused,what a mess.....

sorry for my poor english~

@scottrhoyt
Copy link

So I came smack dab into this issue myself on a project. I am coming to the conclusion that the wireframe needs to know a lot more about the interactor layers. I also believe the instantiation of the entire module should happen in the wireframe. In essense the wireframe is the transition object you talk about. It should know how to pull data and dependencies from one module to insert into another at the interactor level up. This doesn't seem to be super "clean" but neither does passing massive amounts of data through presenters and wireframes on each side. What do you guys think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants