亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? pat5j.htm

?? java設計范式.rar
?? HTM
字號:
<HTML><HEAD>	<TITLE>Template Method</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><A NAME="TemplateMethod"></A><A NAME="intent"></A><H2><A HREF="#motivation"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Motivation"></A> Intent</H2> <A NAME="auto1000"></A><P>Define the skeleton of an algorithm in an operation, deferring somesteps to subclasses. Template Method lets subclasses redefinecertain steps of an algorithm without changing the algorithm'sstructure.</P><A NAME="motivation"></A><H2><A HREF="#applicability"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Applicability"></A> Motivation</H2> <A NAME="auto1001"></A><P>Consider an application framework that provides Application andDocument classes.  The Application class is responsible for openingexisting documents stored in an external format, such as a file.  ADocument object represents the information in a document once it'sread from the file.</P><A NAME="auto1002"></A><P>Applications built with the framework can subclass Application andDocument to suit specific needs.  For example, a drawing applicationdefines DrawApplication and DrawDocument subclasses; a spreadsheetapplication defines SpreadsheetApplication and SpreadsheetDocumentsubclasses.<A NAME="325c"></A><P ALIGN=CENTER><IMG SRC="Pictures/tmeth007.gif"></P><A NAME="auto1003"></A><P>The abstract Application class defines the algorithm for opening andreading a document in its OpenDocument operation:</P><A NAME="auto1004"></A><PRE>    void Application::OpenDocument (const char* name) {        if (!CanOpenDocument(name)) {            // cannot handle this document            return;        }            Document* doc = DoCreateDocument();            if (doc) {            _docs->AddDocument(doc);            AboutToOpenDocument(doc);            doc->Open();            doc->DoRead();        }    }</PRE><A NAME="auto1005"></A><P>OpenDocument defines each step for opening a document.  It checks ifthe document can be opened, creates the application-specific Documentobject, adds it to its set of documents, and reads the Document from afile.</P><A NAME="deftempmeth"></A><P>We call OpenDocument a <STRONG>template method</STRONG>.  A template methoddefines an algorithm in terms of abstract operations that subclassesoverride to provide concrete behavior.  Application subclasses definethe steps of the algorithm that check if the document can be opened(CanOpenDocument) and that create the Document (DoCreateDocument).Document classes define the step that reads the document (DoRead).The template method also defines an operation that lets Applicationsubclasses know when the document is about to be opened(AboutToOpenDocument), in case they care.</P><A NAME="auto1006"></A><P>By defining some of the steps of an algorithm using abstractoperations, the template method fixes their ordering, but it letsApplication and Document subclasses vary those steps to suit theirneeds.</P><A NAME="applicability"></A><H2><A HREF="#structure"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Structure"></A> Applicability</H2> <A NAME="auto1007"></A><P>The Template Method pattern should be used</P><UL><A NAME="auto1008"></A><LI>to implement the invariant parts of an algorithm once and leave it upto subclasses to implement the behavior that can vary.</LI><A NAME="auto1009"></A><P></P><A NAME="refactoring"></A><LI>when common behavior among subclasses should be factored and localizedin a common class to avoid code duplication. This is a good example of"refactoring to generalize" as described by Opdyke andJohnson [<A HREF="bibfs.htm#opdyke-johnson_refactoring2" TARGET="_mainDisplayFrame">OJ93</A>].  You first identify thedifferences in the existing code and then separate the differencesinto new operations.  Finally, you replace the differing code with atemplate method that calls one of these new operations.</LI><A NAME="auto1010"></A><P></P><A NAME="auto1011"></A><LI>to control subclasses extensions. You can define a template methodthat calls "hook" operations (see Consequences) at specific points,thereby permitting extensions only at those points.</LI></UL><A NAME="structure"></A><H2><A HREF="#participants"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Participants"></A> Structure</H2> <P ALIGN=CENTER><IMG SRC="Pictures/tmethod.gif"></P><A NAME="participants"></A><H2><A HREF="#collaborations"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Collaborations"></A> Participants</H2><UL><A NAME="auto1012"></A><LI><B>AbstractClass</B> (Application)<A NAME="auto1013"></A><P></P><UL><A NAME="oper-primitive1"></A><LI>defines abstract <STRONG>primitive operations</STRONG> that concretesubclasses define to implement steps of an algorithm.</LI><A NAME="auto1014"></A><P></P><A NAME="skeleton"></A><LI>implements a template method defining the skeleton of an algorithm.The template method calls primitive operations as well as operationsdefined in AbstractClass or those of other objects.</LI></UL><A NAME="auto1015"></A><P></P><A NAME="auto1016"></A><LI><B>ConcreteClass</B> (MyApplication)<A NAME="auto1017"></A><P></P><UL><A NAME="auto1018"></A><LI>implements the primitive operations to carry out subclass-specificsteps of the algorithm.</LI></UL></UL><A NAME="collaborations"></A><H2><A HREF="#consequences"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Consequences"></A> Collaborations</H2><UL><A NAME="auto1019"></A><LI>ConcreteClass relies on AbstractClass to implement the invariant steps of the algorithm.</LI></UL><A NAME="consequences"></A><H2><A HREF="#implementation"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Implementation"></A> Consequences</H2> <A NAME="auto1020"></A><P>Template methods are a fundamental technique for code reuse.  They areparticularly important in class libraries, because they are the meansfor factoring out common behavior in library classes.</P><A NAME="auto1021"></A><P>Template methods lead to an inverted control structure that'ssometimes referred to as "the Hollywood principle," that is, "Don'tcall us, we'll call you" [<A HREF="bibfs.htm#hollywood-principle" TARGET="_mainDisplayFrame">Swe85</A>].  This refers tohow a parent class calls the operations of a subclass and not theother way around.</P><A NAME="oper-concrete"></A><P>Template methods call the following kinds of operations:</P><UL><A NAME="auto1022"></A><LI>concrete operations (either on the ConcreteClass or onclient classes);</LI><A NAME="auto1023"></A><P></P><A NAME="auto1024"></A><LI>concrete AbstractClass operations (i.e., operations that aregenerally useful to subclasses);</LI><A NAME="auto1025"></A><P></P><A NAME="oper-primitive2"></A><LI>primitive operations (i.e., abstract operations);</LI><A NAME="auto1026"></A><P></P><A NAME="auto1027"></A><LI>factory methods (see <A HREF="pat3cfs.htm" TARGET="_mainDisplayFrame">Factory Method (107)</A>);and</LI><A NAME="auto1028"></A><P></P><A NAME="auto1029"></A><LI><STRONG>hook operations</STRONG>, which provide default behavior thatsubclasses can extend if necessary. A hook operation often doesnothing by default.</LI></UL><A NAME="auto1030"></A><P>It's important for template methods to specify which operations arehooks (<EM>may</EM> be overridden) and which are abstract operations(<EM>must</EM> be overridden). To reuse an abstract class effectively,subclass writers must understand which operations are designed foroverriding.</P><A NAME="auto1031"></A><P>A subclass can <EM>extend</EM> a parent class operation's behavior byoverriding the operation and calling the parent operation explicitly:<A NAME="auto1032"></A><PRE>    void DerivedClass::Operation () {        // DerivedClass extended behavior        ParentClass::Operation();    }</PRE><A NAME="auto1033"></A><P>Unfortunately, it's easy to forget to call the inherited operation.We can transform such an operation into a template method to givethe parent control over how subclasses extend it. The idea is tocall a hook operation from a template method in the parent class.Then subclasses can then override this hook operation:</P><A NAME="auto1034"></A><PRE>    void ParentClass::Operation () {        // ParentClass behavior        HookOperation();    }</PRE><A NAME="auto1035"></A><P><CODE>HookOperation</CODE> does nothing in <CODE>ParentClass</CODE>:</P><A NAME="auto1036"></A><PRE>    void ParentClass::HookOperation () { }</PRE><A NAME="auto1037"></A><P>Subclasses override <CODE>HookOperation</CODE> to extend itsbehavior:</P><A NAME="auto1038"></A><PRE>    void DerivedClass::HookOperation () {         // derived class extension    }</PRE><A NAME="implementation"></A><H2><A HREF="#samplecode"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Sample Code"></A> Implementation</H2> <A NAME="auto1039"></A><P>Three implementation issues are worth noting:</P><OL><A NAME="auto1040"></A><LI><EM>Using C++ access control.</EM>In C++, the primitive operations that a template method calls can bedeclared protected members. This ensures that they are only called bythe template method. Primitive operations that <EM>must</EM> be overridden aredeclared pure virtual. The template method itself should not beoverridden; therefore you can make the template method a nonvirtualmember function.</LI><A NAME="auto1041"></A><P></P><A NAME="auto1042"></A><LI><EM>Minimizing primitive operations.</EM>An important goal in designing template methods is to minimize thenumber of primitive operations that a subclass must override to fleshout the algorithm. The more operations that need overriding, the moretedious things get for clients.</LI><A NAME="auto1043"></A><P></P><A NAME="templ-naming"></A><LI><EM>Naming conventions.</EM>You can identify the operations that should be overridden by adding aprefix to their names. For example, the MacApp framework for Macintoshapplications [<A HREF="bibfs.htm#macapp" TARGET="_mainDisplayFrame">App89</A>] prefixes template method names with "Do-":"DoCreateDocument", "DoRead", and so forth.</LI></OL><A NAME="samplecode"><A><H2><A HREF="#knownuses"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Known Uses"></A> Sample Code</H2> <A NAME="auto1044"></A><P>The following C++ example shows how a parent class can enforce aninvariant for its subclasses. The example comes from NeXT'sAppKit [<A HREF="bibfs.htm#NeXT_AppKit" TARGET="_mainDisplayFrame">Add94</A>]. Consider a class <CODE>View</CODE> that supportsdrawing on the screen. <CODE>View</CODE> enforces the invariant that itssubclasses can draw into a view only after it becomes the "focus,"which requires certain drawing state (for example, colors and fonts) tobe set up properly.</P><A NAME="auto1045"></A><P>We can use a <CODE>Display</CODE> template method to set up this state.<CODE>View</CODE> defines two concrete operations,<CODE>SetFocus</CODE> and <CODE>ResetFocus</CODE>, that set up and clean upthe drawing state, respectively.  <CODE>View</CODE>'s <CODE>DoDisplay</CODE>hook operation performs the actual drawing.  <CODE>Display</CODE> calls<CODE>SetFocus</CODE> before <CODE>DoDisplay</CODE> to set up the drawingstate; <CODE>Display</CODE> calls <CODE>ResetFocus</CODE> afterwards torelease the drawing state.</P><A NAME="auto1046"></A><PRE>    void View::Display () {        SetFocus();        DoDisplay();        ResetFocus();    }</PRE><A NAME="auto1047"></A><P>To maintain the invariant, the <CODE>View</CODE>'s clients always call<CODE>Display</CODE>, and <CODE>View</CODE> subclasses always override<CODE>DoDisplay</CODE>.</P><A NAME="auto1048"></A><P><CODE>DoDisplay</CODE> does nothing in <CODE>View</CODE>:</P><A NAME="auto1049"></A><PRE>    void View::DoDisplay () { }</PRE><A NAME="auto1050"></A><P>Subclasses override it to add their specific drawing behavior:</P><A NAME="auto1051"></A><PRE>    void MyView::DoDisplay () {        // render the view's contents    }</PRE><A NAME="knownuses"><A><H2><A HREF="#relatedpatterns"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: Related Patterns"></A> Known Uses</H2> <A NAME="auto1052"></A><P>Template methods are so fundamental that they can be found in almostevery abstract class.  Wirfs-Brock et al. [<A HREF="bibfs.htm#doosw_www" TARGET="_mainDisplayFrame">WBWW90,</A><A HREF="bibfs.htm#wirfs-brock_cacm" TARGET="_mainDisplayFrame"> WBJ90</A>] provide a good overview anddiscussion of template methods.</P><A NAME="relatedpatterns"></A><H2><A HREF="#last"><IMG SRC="gifsb/down3.gif" BORDER=0 ALT="next: navigation"></A> Related Patterns</H2> <A NAME="auto1053"></A><P><A HREF="pat3cfs.htm" TARGET="_mainDisplayFrame">Factory Methods (107)</A>are often called by template methods. In the Motivation example,the factory method DoCreateDocument is called by the template methodOpenDocument.</P><A NAME="auto1054"></A><P><A HREF="pat5ifs.htm" TARGET="_mainDisplayFrame">Strategy (315)</A>:Template methods use inheritance to vary part of an algorithm.Strategies use delegation to vary the entire algorithm.</P><A NAME="last"></A><P><A HREF="#intent"><IMG SRC="gifsb/up3.gif" BORDER=0></A><BR><A HREF="pat5kfs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/rightar3.gif"        ALIGN=TOP BORDER=0></A> <A HREF="pat5kfs.htm"        TARGET="_mainDisplayFrame">Visitor</A><BR><A HREF="pat5ifs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/leftarr3.gif"        ALIGN=TOP BORDER=0></A> <A HREF="pat5ifs.htm"        TARGET="_mainDisplayFrame">Strategy</A></P></BODY></HTML>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲电影激情视频网站| 午夜国产不卡在线观看视频| 最新国产の精品合集bt伙计| 亚洲国产精品麻豆| 国产成人aaaa| 3d动漫精品啪啪| 中文字幕中文在线不卡住| 天天综合日日夜夜精品| 99riav一区二区三区| 欧美精品一区二区在线观看| 亚洲一区av在线| 国产在线精品免费av| 欧美日韩一区高清| 综合色中文字幕| 成人免费毛片嘿嘿连载视频| 欧美不卡一区二区三区四区| 亚洲伊人色欲综合网| av爱爱亚洲一区| 国产精品网站在线观看| 国产老肥熟一区二区三区| 日韩三级视频中文字幕| 亚洲永久免费av| 色哟哟国产精品| 亚洲人成网站精品片在线观看| 国产福利不卡视频| 2020国产成人综合网| 狠狠久久亚洲欧美| 欧美一二三区在线观看| 五月综合激情日本mⅴ| 欧美日韩国产乱码电影| 一区二区三区四区精品在线视频| www.久久久久久久久| 国产精品三级电影| 成人av动漫网站| 国产精品麻豆视频| 成人免费视频一区二区| 国产精品视频观看| 成人av网站免费观看| 日本一二三四高清不卡| www.av亚洲| 自拍偷拍国产精品| 色一情一伦一子一伦一区| 亚洲免费av网站| 91久久精品日日躁夜夜躁欧美| 亚洲毛片av在线| 欧美日韩三级一区| 日韩精品1区2区3区| 精品电影一区二区三区| 国产福利不卡视频| 亚洲少妇30p| 欧美日韩小视频| 久久草av在线| 国产精品全国免费观看高清| 97se亚洲国产综合在线| 亚洲电影一区二区| 欧美一区二区三级| 国产激情91久久精品导航| 成人欧美一区二区三区黑人麻豆| 色综合激情久久| 蜜臀a∨国产成人精品| 国产三级精品视频| 在线精品观看国产| 久久黄色级2电影| 国产精品毛片久久久久久久| 欧美日韩综合一区| 日本美女视频一区二区| 国产丝袜在线精品| 欧美亚洲一区三区| 激情欧美一区二区三区在线观看| 国产精品久久久久一区二区三区共| 欧洲在线/亚洲| 激情成人综合网| 一区二区国产盗摄色噜噜| 日韩视频免费直播| 91女人视频在线观看| 蜜臀av性久久久久av蜜臀妖精| 成人欧美一区二区三区黑人麻豆| 欧美一区二区三区在线看| www.亚洲色图| 久久精品国产精品亚洲精品| 亚洲色图欧洲色图婷婷| 日韩女优制服丝袜电影| 色综合亚洲欧洲| 国产一区二区看久久| 偷窥少妇高潮呻吟av久久免费| 日本一区二区三级电影在线观看 | 欧美性三三影院| 国产一区二区三区四| 性感美女极品91精品| 国产精品丝袜一区| 欧美成人一区二区三区片免费 | 91精品国产麻豆国产自产在线 | 国产成人精品免费视频网站| 亚洲福利一区二区三区| 亚洲三级小视频| 国产欧美精品一区二区色综合朱莉| 精品视频1区2区| 91丨porny丨国产| 国产成人亚洲综合a∨猫咪| 日本午夜精品一区二区三区电影 | 欧美激情在线看| 欧美成人乱码一区二区三区| 欧美日韩精品免费观看视频| 99v久久综合狠狠综合久久| 国产69精品久久99不卡| 精品一区二区综合| 婷婷六月综合亚洲| 亚洲图片欧美视频| 亚洲在线视频一区| 亚洲另类中文字| 亚洲欧美福利一区二区| 中文字幕第一区二区| 国产欧美日韩亚州综合| 精品国内片67194| 精品国产第一区二区三区观看体验| 666欧美在线视频| 欧美另类videos死尸| 欧美片网站yy| 欧美一区二区三区视频| 日韩欧美国产1| 欧美xxxxxxxxx| 26uuu精品一区二区三区四区在线| 日韩久久免费av| 国产午夜精品久久久久久免费视 | 毛片基地黄久久久久久天堂| 日本在线不卡视频一二三区| 蜜臀av在线播放一区二区三区| 精品在线播放免费| 国产精品亚洲专一区二区三区| 国产91精品一区二区| 成人激情小说乱人伦| 91美女蜜桃在线| 欧美三级一区二区| 日韩一级大片在线| 精品国产百合女同互慰| 国产日产亚洲精品系列| 1000部国产精品成人观看| 一区二区三区在线视频播放| 亚洲午夜免费福利视频| 男女激情视频一区| 激情欧美日韩一区二区| 97精品超碰一区二区三区| 欧美日韩国产综合久久| 日韩片之四级片| 国产精品国产a级| 亚洲自拍偷拍av| 激情综合网天天干| www.日韩大片| 欧美精选一区二区| 久久久久国产一区二区三区四区| 中文字幕一区免费在线观看| 亚洲亚洲精品在线观看| 激情五月婷婷综合| 成人av综合一区| 日韩一区二区三区免费看| 日本一区二区三区四区在线视频 | 亚洲免费观看视频| 日韩电影在线观看电影| 国产成人在线视频免费播放| 91官网在线观看| 欧美精品一区二区在线播放 | 在线免费亚洲电影| 26uuu精品一区二区三区四区在线 26uuu精品一区二区在线观看 | 午夜精品在线视频一区| 国产美女娇喘av呻吟久久| 欧美伊人久久大香线蕉综合69| 久久夜色精品一区| 一区二区日韩av| 懂色一区二区三区免费观看| 欧美日韩mp4| 综合中文字幕亚洲| 国产一区视频在线看| 欧美人与z0zoxxxx视频| 亚洲私人黄色宅男| 国产裸体歌舞团一区二区| 欧美日韩久久一区| 亚洲欧洲精品一区二区三区 | 不卡电影免费在线播放一区| 日韩一卡二卡三卡| 亚洲国产精品久久久久秋霞影院 | 国产精品一品视频| 欧美一区二区三区视频| 亚洲图片欧美色图| 色婷婷亚洲一区二区三区| 国产欧美一区二区三区在线老狼| 免费欧美在线视频| 在线观看www91| 亚洲三级免费观看| 成人av在线资源网站| 国产视频视频一区| 国内精品写真在线观看| 欧美一区二区视频观看视频| 午夜欧美大尺度福利影院在线看| 色偷偷一区二区三区| 国产精品久久久久一区二区三区| 国产精品亚洲视频| 国产日韩欧美综合在线| 国产成人鲁色资源国产91色综| 精品动漫一区二区三区在线观看| 另类小说欧美激情|