Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it necessary that a delegate message should always have void as a return type?

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 ?

like image 615
Amogh Talpallikar Avatar asked Mar 19 '13 11:03

Amogh Talpallikar


1 Answers

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:

  • A (the view) sends B (the delegate & data source) a message and receives back the data info needed to refresh the view.
like image 72
David Ben Ari Avatar answered Sep 19 '22 12:09

David Ben Ari