?? chap5-0.htm
字號(hào):
<HTML><HEAD> <TITLE>Behavioral Patterns</TITLE><SCRIPT>function setFocus() { if ((navigator.appName != "Netscape") && (parseFloat(navigator.appVersion) == 2)) { return; } else { self.focus(); }}</SCRIPT></HEAD><BODY BGCOLOR = #FFFFFF onLoad="setFocus()";><A NAME="top"></A><!-- <H1>Behavioral Patterns</H1> --><P>Behavioral patterns are concerned with algorithms and theassignment of responsibilities between objects. Behavioral patternsdescribe not just patterns of objects or classes but also the patternsof communication between them. These patterns characterize complexcontrol flow that's difficult to follow at run-time. They shift yourfocus away from flow of control to let you concentrate just on the wayobjects are interconnected.<A NAME="class-v-object-scope"></A><P>Behavioral class patterns use inheritance to distribute behaviorbetween classes. This chapter includes two such patterns.<A HREF="pat5jfs.htm" TARGET="_mainDisplayFrame">Template Method (325)</A> is the simpler and more common ofthe two. A template method is an abstract definition of an algorithm.It defines the algorithm step by step. Each step invokes either anabstract operation or a primitive operation. A subclass fleshes outthe algorithm by defining the abstract operations. The otherbehavioral class pattern is<A HREF="pat5cfs.htm" TARGET="_mainDisplayFrame">Interpreter (243)</A>, whichrepresents a grammar as a class hierarchy and implements aninterpreter as an operation on instances of these classes.<A NAME="behavional_1"></A><P>Behavioral object patterns use object composition rather thaninheritance. Some describe how a group of peer objects cooperate toperform a task that no single object can carry out by itself. Animportant issue here is how peer objects know about each other. Peerscould maintain explicit references to each other, but that wouldincrease their coupling. In the extreme, every object would knowabout every other. The <A HREF="pat5efs.htm" TARGET="_mainDisplayFrame">Mediator (273)</A> pattern avoidsthis by introducing a mediator object between peers. The mediatorprovides the indirection needed for loose coupling.<A NAME="behavional_2"></A><P><A HREF="pat5afs.htm" TARGET="_mainDisplayFrame">Chain of Responsibility (223)</A> provides even loosercoupling. It lets you send requests to an object implicitly through achain of candidate objects. Any candidate may fulfill the requestdepending on run-time conditions. The number of candidates isopen-ended, and you can select which candidates participate in thechain at run-time.<A NAME="behavional_3"></A><P>The <A HREF="pat5gfs.htm" TARGET="_mainDisplayFrame">Observer (293)</A> pattern defines and maintains adependency between objects. The classic example of Observer is inSmalltalk Model/View/Controller, where all views of the model are notified whenever themodel's state changes.<A NAME="behavional_4"></A><P>Other behavioral object patterns are concerned with encapsulatingbehavior in an object and delegating requests to it. The<A HREF="pat5ifs.htm" TARGET="_mainDisplayFrame">Strategy (315)</A> pattern encapsulates an algorithm in anobject. Strategy makes it easy to specify and change the algorithm anobject uses. The <A HREF="pat5bfs.htm" TARGET="_mainDisplayFrame">Command (233)</A> pattern encapsulates arequest in an object so that it can be passed as a parameter, storedon a history list, or manipulated in other ways. The<A HREF="pat5hfs.htm" TARGET="_mainDisplayFrame">State (305)</A> pattern encapsulates the states of an objectso that the object can change its behavior when its state objectchanges. <A HREF="pat5kfs.htm" TARGET="_mainDisplayFrame">Visitor (331)</A> encapsulates behavior that wouldotherwise be distributed across classes, and<A HREF="pat5dfs.htm" TARGET="_mainDisplayFrame">Iterator (257)</A> abstracts the way you access andtraverse objects in an aggregate.<A NAME="behavional_5"></A><A NAME="last"></A><P><A HREF="#top"><IMG SRC="gifsb/up3.gif" BORDER=0></A><BR><A HREF="pat5afs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/rightar3.gif" ALIGN=TOP BORDER=0></A> <A HREF="pat5afs.htm" TARGET="_mainDisplayFrame">Chain of Responsibility</A><BR><A HREF="disc4fs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/leftarr3.gif" ALIGN=TOP BORDER=0></A> <A HREF="disc4fs.htm" TARGET="_mainDisplayFrame">Discussion of Structural Patterns</A></P></BODY></HTML>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -