I tried to figure it out, I promise! There is a lot of information on this, and I'm still flooded with a sea of abstract concepts! I like it when I was a child, and no one could explain to me why a country cannot just print more money and be really rich. I do not linger on most of these things, but for some reason I cannot plunge into this concept, so it would be very useful if someone could describe it as patronizing "talking to a 4-year-old," as slowly as possible
I think that the targeted action makes complete sense to me. This is a useful way to allow browsing to talk to the controller, without having to do a lot. As far as I can understand, the controller object effectively attaches the listener to the view object, so if a certain event occurs in this view (i.e., a button is pressed), it starts the controller method. This may not be technically accurate, but as an abstract explanation, it makes sense to me.
So the sequence:
- The target method is created in the controller object.
- The view is selected and graphically associated with this method.
- In this view, an event occurs that fires the method from the controller.
The protocols and delegates annoy me. I know that this is due to allowing the objects to talk to each other, but I tried to write out my (lack of) understanding so far and simply deleted it, since I think it’s better not to dissolve the nodes in my current thinking, but just wipe the slate and run again. If someone can kindly spend some time explaining the purpose
- Using delegates / protocols as opposed to a goal / action
- Components of the code and where it lives.
- The sequence of events that occur when using the process
I would be eternally grateful.
Judging by some comments on other explanations, I feel that I'm not the only one who got a little lost, so I hope this will be of general use. Many thanks!
Edit:
Well, as I thought, maybe if I just lay out my understanding, people can fix me, and it can make it easier.
My sample is taken from Apple Docs , with a window as a viewer and WindowDelegate as a delegate, where clicking on the close button of a window causes "should I close?" message to the delegate.
Components of the code: Window (view) WindowDelegate (View Controller?)
- Declare a protocol that a delegate can use in the interface section of the window (View).
- Make an instance of the delegate in the window.
- Indicate that WindowDelegate implements the Window protocol by including an interface in it. (is it a little shaky here?)
- Write the required implementation of the methods in the implementation section of WindowDelegate (View Controller).
- In a specific event, the window will send a message to WindowDelegate with specific information.
- WindowDelegate will handle this and return a response.
Everywhere along the right lines?