# Import
# Import "TView.h"
# Import "TActive.h"
int main (int argc, const char * argv [])
{
@ Autoreleasepool {
TView * v = [[TView alloc] init];
TActive * a = [[TActive alloc] init];
a.tView = v;
v.Delegate = a;
[V onClick];
}
return 0;
}
TView.h file:
@ Protocol Message
- (Void) onClickMsg;
@ End
@ Interface TView: NSObject
{
NSString * TViewText;
idDelegate;
}
@ Property (nonatomic, retain) idDelegate;
@ Property (nonatomic, retain) TView * TviewText;
- (Void) onClick;
- (TView *) init;
- (Void) Show;
@ End
TView.m file:
# Import "TView.h"
@ Implementation TView
@ Synthesize Delegate;
@ Synthesize TviewText;
- (TView *) init
{
self = [super init];
if (self)
{
NSLog (@ "Internet please click me");
}
return self;
}
- (Void) onClick
{
NSLog (@ "button is clicked.");
[Delegate onClickMsg];
}
- (Void) Show
{
NSLog ("download data from the Internet, I will show it." @);
NSLog (@ "to download data from the Internet is:% @", TviewText);
NSLog (@ "Show finished Thank you for using goodbye.!");
}
@ End
TActive.h file
# Import
# Import "TView.h"
@ Interface TActive: NSObject
{
TView * tView;
}
@ Property (nonatomic, retain) TView * tView;
@ End
TActive.m file
# Import "TActive.h"
@ Implementation TActive
@ Synthesize tView;
- (Void) onClickMsg
{
NSLog (@ "to download data from the Internet.");
NSLog (@ "downloaded data are: China");
[TView setTviewText: @ "China"];
NSLog (@ "the download is complete.");
[TView Show];
}
@ End
Reply:
Results of operation:
2012-04-20 16:15:20.953 Day8 [233:403] online, please click on my
2012-04-20 16:15:20.989 Day8 [233:403] button is clicked.
2012-04-20 16:15:20.993 Day8 [233:403] download data from the Internet.
2012-04-20 16:15:20.995 Day8 [233:403] downloaded data are: China
2012-04-20 16:15:20.998 Day8 [233:403] downloaded.
2012-04-20 16:15:21.001 Day8 [233:403] data downloaded from the Internet. I will show it
2012-04-20 16:15:21.003 Day8 [233:403] data downloaded from the Internet are: China
2012-04-20 16:15:21.005 Day8 [233:403] Thank you for the use of the display is completed. Goodbye!
Reply:
A and B signed an agreement to abide by A and B, the agreement is to allow Party B to provide the data downloaded from the Internet.
Reply:
Ah, nearly what it means.
Reply:
Ah, nearly what it means.
Reply:
The so-called commission is a design pattern is probably one thing to another person handed down.
For example, your boss will receive a corporate job, then ye programmer to complete.
You do not write it and protocols confused.
http://blog.langyufei.com/?p=273
You look at it.
Reply:
Who defined the protocol, who implement the protocol. Understood, there is the case. Write more than just fine
Reply:
@ Interface TView: NSObject
Here do not add
Are generally entrusted to implement the protocol, @ interface TActive: NSObject
Reply:
White said the agreement is a contract. Both sides need to comply with an interactive constraints. The mentioned here is the "Agency Agreement" concept, which should be a decoupling of objects interact to solve a design pattern. For example, the following scenario: There are two objects A and B, A B needs to call a method in a way, we usually add pointers application of B in A, this is no problem, but we might also object B's A method to call, if it is according to this design, it is likely there will be a circular reference.
In fact, nothing more than objects assume two roles in the process of interaction, a Data receiver, 2. Data sender. In the "Agency Agreement" model, the data transmitted by the data receiver comprises a pointer.
@ Interface MyWidget: BaseWidget {
id
}
@ Property (assign) id
@ End
The recipient of the data is required to achieve agreement
@ Protocal BaseWidgetDelegate;
@ Interface WidgetManager: NSObject
....
@ End
Reply:
Applications, the agent for the OC in the system, will call on it, some of the functions entrusted to Apple to achieve (packaged), is a pointer object by value handwritten agency essentially Well, to call themselves to design their own (own realization)
Remember the agent slowly to understand format is also a choice
Personal opinion
No comments:
Post a Comment