Hello everyone! What is the best way to implement ...
# decompose
m
Hello everyone! What is the best way to implement behaviour like startActivityForResult? I want to call a child component that returns an object after some actions are done (and pops out of the stack).
a
You can just pass a callback into that child component. The child component calls the callback with a result, the parent component pops the stack and handles the result.
m
Btw, a component interface is a "contract" with the parent component or a "contract" with the component's content? For example, we might need to specify in a component some callbacks (we have an example above), sometimes we want to specify some variables and methods to be called by content. Should we define these two "obligations" or "contracts" in the same component, or for the content (UI) part we can move it to some other classes?
a
I don't clearly understand the question. First of all, interfaces are optional. One may like or may not like having Interfaces (e.g. when there is only one implementation). If you prefer interfaces, then again it's up to you how you design. I usually treat interfaces as a public API of the component. Both the UI and the parent component can communicate with the interface because they both see the interface.