I have a scenario where Obj A sends a delegate message to Obj B say on pressing a button. Obj B takes some action based on delegate call.
Obj A wants to show something on screen based on the result of what happened after that delegate message was called.
Say Obj B maintains a counter, of how many times that action took place.
So When Obj A presses the buttons and calls the delegate method, is it a good idea for that delegate method to return a value, in my case the current counter ?
so that Obj A can display the counter updated value.
In this case same message is acting as both a Delegate and a DataSource.
For me Obj A is a View and Obj B is View Controller.
Is my implementation flawed ?
I like your implementation.
Even if it doesn't differentiate between the delegate and the datasource roles it combines them in a more simplistic way.
I guess the appropriate way to implement as far as MVC concepts is:
A (the view) sends B (the delegate) a message saying "I was tapped" or something similiar.
B (the delegate) acts as needed and sends back to A a message saying "reloadData".
A asks B (as the data source now) for the data to display.
because in your case the delegate and the data source are the same object, as it happens in many other cases, it seems to me very plausible and not at all flawed to implement the flow as you did:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With