You should first have a look at the documentation of NSWindow. Now the class NSWindow is huge, does tons of things, and even though you could create a subclass and override methods in it, Cocoa uses a different method. NSWindow decides in which situations it wants you (the application developer) to handle a situation. To do that, you create a delegate object and install it into the window by calling [myWindow setDelegate: myDelegate]. The delegate object only implements the dozen methods that are marked as "delegate" methods in NSWindow.
For example, to handle closing a window there are two delegate methods. One is called "windowShouldClose". If the user clicks into the red close button and releases the mouse, NSWindow calls the delegates "windowShouldClose" method. At that point, your code decides whether you actually want the window to close or not. For example, if the window contains a document with unsaved changes, "windowShouldClose" will ask the user whether they want to save the changes, and if they press "Cancel" your delegate method returns "NO" and the window isn't closed. You don't close the window yourself, you only do everything else that needs doing.
The other method is "windowWillClose". NSWindow calls that method just before it closes the window. There is no way to prevent it from closing the window, your delegate had its chance when "windowShouldClose" was called. All you do is clean up everything you want to clean up before the window disappears.