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

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

?? pat4f.htm

?? java設計范式.rar
?? HTM
?? 第 1 頁 / 共 2 頁
字號:
</LI><A NAME="flywt-mng-shar"></A><LI><EM>Managing shared objects.</EM>Because objects are shared, clients shouldn't instantiate themdirectly.  FlyweightFactory lets clients locate a particularflyweight.  FlyweightFactory objects often use an associative store tolet clients look up flyweights of interest. For example, theflyweight factory in the document editor example can keep a table offlyweights indexed by character codes. The manager returns the properflyweight given its code, creating the flyweight if it does notalready exist.<A NAME="auto1056"></A><P>Sharability also implies some form of reference counting or garbagecollection to reclaim a flyweight's storage when it's no longerneeded.  However, neither is necessary if the number of flyweights isfixed and small (e.g., flyweights for the ASCII character set).  Inthat case, the flyweights are worth keeping around permanently.</P></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="auto1057"></A><P>Returning to our document formatter example, we can define a<CODE>Glyph</CODE> base class for flyweight graphical objects.Logically, glyphs are Composites (see <A HREF="pat4cfs.htm" TARGET="_mainDisplayFrame">Composite (163)</A>) that have graphical attributes and candraw themselves.  Here we focus on just the font attribute, butthe same approach can be used for any other graphical attributesa glyph might have.</P><A NAME="auto1058"></A><PRE>    class Glyph {    public:        virtual ~Glyph();            virtual void Draw(Window*, GlyphContext&amp;);            virtual void SetFont(Font*, GlyphContext&amp;);        virtual Font* GetFont(GlyphContext&amp;);            virtual void First(GlyphContext&amp;);        virtual void Next(GlyphContext&amp;);        virtual bool IsDone(GlyphContext&amp;);        virtual Glyph* Current(GlyphContext&amp;);            virtual void Insert(Glyph*, GlyphContext&amp;);        virtual void Remove(GlyphContext&amp;);    protected:        Glyph();    };</PRE><A NAME="auto1059"></A><P>The <CODE>Character</CODE> subclass just stores a character code:<A NAME="auto1060"></A><PRE>    class Character : public Glyph {    public:        Character(char);            virtual void Draw(Window*, GlyphContext&amp;);    private:        char _charcode;    };</PRE><A NAME="auto1061"></A><P>To keep from allocating space for a font attribute in every glyph,we'll store the attribute extrinsically in a <CODE>GlyphContext</CODE>object.  <CODE>GlyphContext</CODE> acts as a repository of extrinsicstate. It maintains a compact mapping between a glyph and its font(and any other graphical attributes it might have) in differentcontexts.  Any operation that needs to know the glyph's font in agiven context will have a <CODE>GlyphContext</CODE> instance passed to itas a parameter.  The operation can then query the<CODE>GlyphContext</CODE> for the font in that context.  The contextdepends on the glyph's location in the glyph structure.  Therefore<CODE>Glyph</CODE>'s child iteration and manipulation operations mustupdate the <CODE>GlyphContext</CODE> whenever they're used.</P><A NAME="auto1062"></A><PRE>    class GlyphContext {    public:        GlyphContext();        virtual ~GlyphContext();            virtual void Next(int step = 1);        virtual void Insert(int quantity = 1);            virtual Font* GetFont();        virtual void SetFont(Font*, int span = 1);    private:        int _index;        BTree* _fonts;    };</PRE><A NAME="auto1063"></A><P><CODE>GlyphContext</CODE> must be kept informed of the current positionin the glyph structure during traversal.  <CODE>GlyphContext::Next</CODE>increments <CODE>_index</CODE> as the traversal proceeds.<CODE>Glyph</CODE> subclasses that have children (e.g., <CODE>Row</CODE> and<CODE>Column</CODE>) must implement <CODE>Next</CODE> so that it calls<CODE>GlyphContext::Next</CODE> at each point in the traversal.</P><A NAME="btree"></A><P><CODE>GlyphContext::GetFont</CODE> uses the index as a key into a<CODE>BTree</CODE> structure that stores the glyph-to-font mapping.Each node in the tree is labeled with the length of the string for whichit gives font information.  Leaves in the tree point to a font, whileinterior nodes break the string into substrings, one for each child.</P><A NAME="auto1064"></A><P>Consider the following excerpt from a glyph composition:</P><P ALIGN=CENTER><IMG SRC="Pictures/btree097.gif"></P><A NAME="auto1065"></A><P>The <CODE>BTree</CODE> structure for font information might look like</P><P ALIGN=CENTER><IMG SRC="Pictures/btree-1.gif"></P><A NAME="auto1066"></A><P>Interior nodes define ranges of glyph indices. <CODE>BTree</CODE> isupdated in response to font changes and whenever glyphs are added toor removed from the glyph structure.  For example, assuming we're atindex 102 in the traversal, the following code sets the font of eachcharacter in the word "expect" to that of the surrounding text (thatis, <CODE>times12</CODE>, an instance of <CODE>Font</CODE> for 12-pointTimes Roman):</P><A NAME="auto1067"></A><PRE>    GlyphContext gc;    Font* times12 = new Font("Times-Roman-12");    Font* timesItalic12 = new Font("Times-Italic-12");    // ...        gc.SetFont(times12, 6);</PRE><A NAME="auto1068"></A><P>The new <CODE>BTree</CODE> structure (with changes shown in black) lookslike</P><P ALIGN=CENTER><IMG SRC="Pictures/btree-2.gif"></P><A NAME="auto1069"></A><P>Suppose we add the word "don't&nbsp;" (including a trailing space) in12-point Times Italic before "expect."  The following code informs the<CODE>gc</CODE> of this event, assuming it is still at index 102:</P><A NAME="auto1070"></A><PRE>    gc.Insert(6);    gc.SetFont(timesItalic12, 6);</PRE><A NAME="auto1071"></A><P>The <CODE>BTree</CODE> structure becomes</P><P ALIGN=CENTER><IMG SRC="Pictures/btree-3.gif"></P><A NAME="auto1072"></A><P>When the <CODE>GlyphContext</CODE> is queried for the font ofthe current glyph, it descends the <CODE>BTree</CODE>, adding upindices as it goes until it finds the font for the current index.Because the frequency of font changes is relatively low, the treestays small relative to the size of the glyph structure.  Thiskeeps storage costs down without an inordinate increase in look-uptime.<A NAME="fn3"></A><A HREF="#footnote3"><SUP>3</SUP></A></P><A NAME="flywt-fact"></A><P>The last object we need is a FlyweightFactory that creates glyphs andensures they're shared properly.  Class <CODE>GlyphFactory</CODE>instantiates <CODE>Character</CODE> and other kinds of glyphs.  We onlyshare <CODE>Character</CODE> objects; composite glyphs are far lessplentiful, and their important state (i.e., their children) isintrinsic anyway.</P><A NAME="auto1073"></A><PRE>    const int NCHARCODES = 128;        class GlyphFactory {    public:        GlyphFactory();        virtual ~GlyphFactory();            virtual Character* CreateCharacter(char);        virtual Row* CreateRow();        virtual Column* CreateColumn();        // ...    private:        Character* _character[NCHARCODES];    };</PRE><A NAME="auto1074"></A><P>The <CODE>_character</CODE> array contains pointers to<CODE>Character</CODE> glyphs indexed by character code.  The array isinitialized to zero in the constructor.</P><A NAME="auto1075"></A><PRE>    GlyphFactory::GlyphFactory () {        for (int i = 0; i < NCHARCODES; ++i) {             _character[i] = 0;        }    }</PRE><A NAME="auto1076"></A><P><CODE>CreateCharacter</CODE> looks up a character in the characterglyph in the array, and it returns the corresponding glyph if itexists.  If it doesn't, then <CODE>CreateCharacter</CODE> createsthe glyph, puts it in the array, and returns it:</P><A NAME="auto1077"></A><PRE>    Character* GlyphFactory::CreateCharacter (char c) {        if (!_character[c]) {            _character[c] = new Character(c);        }            return _character[c];    }</PRE><A NAME="auto1078"></A><P>The other operations simply instantiate a new object each time they'recalled, since noncharacter glyphs won't be shared:</P><A NAME="auto1079"></A><PRE>    Row* GlyphFactory::CreateRow () {        return new Row;    }        Column* GlyphFactory::CreateColumn () {        return new Column;    }</PRE><A NAME="auto1080"></A><P>We could omit these operations and let clients instantiate unsharedglyphs directly.  However, if we decide to make these glyphs sharablelater, we'll have to change client code that creates them.</P><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="auto1081"></A><P>The concept of flyweight objects was first described and explored as adesign technique in InterViews 3.0 [<A HREF="bibfs.htm#interviews_glyphs" TARGET="_mainDisplayFrame">CL90</A>]. Itsdevelopers built a powerful document editor called Doc as a proof ofconcept [<A HREF="bibfs.htm#calder_doc" TARGET="_mainDisplayFrame">CL92</A>]. Doc uses glyph objects to represent eachcharacter in the document.  The editor builds one Glyph instance foreach character in a particular style (which defines its graphicalattributes); hence a character's intrinsic state consists of thecharacter code and its style information (an index into a styletable).<A NAME="fn4"></A><A HREF="#footnote4"><SUP>4</SUP></A>That means only position is extrinsic, making Doc fast.  Documents arerepresented by a class Document, which also acts as theFlyweightFactory.  Measurements on Doc have shown that sharingflyweight characters is quite effective.  In a typical case, adocument containing 180,000 characters required allocation of only 480character objects.</P><A NAME="et-use-flywt"></A><P>ET++ [<A HREF="bibfs.htm#et++" TARGET="_mainDisplayFrame">WGM88</A>] uses flyweights to support look-and-feelindependence.<A NAME="fn5"></A><A HREF="#footnote5"><SUP>5</SUP></A>The look-and-feel standard affects thelayout of user interface elements (e.g., scroll bars, buttons,menus&#151;known collectively as "widgets") and their decorations(e.g., shadows, beveling).  A widget delegates all its layout anddrawing behavior to a separate Layout object.  Changing the Layoutobject changes the look and feel, even at run-time.</P><A NAME="auto1082"></A><P>For each widget class there is a corresponding Layout class (e.g.,ScrollbarLayout, MenubarLayout, etc.). An obvious problem with thisapproach is that using separate layout objects doubles the number ofuser interface objects: For each user interface object there is anadditional Layout object.  To avoid this overhead, Layout objects areimplemented as flyweights.  They make good flyweights because theydeal mostly with defining behavior, and it's easy to pass them whatlittle extrinsic state they need to lay out or draw an object.</P><A NAME="auto1083"></A><P>The Layout objects are created and managed by Look objects. The Lookclass is an <A HREF="pat3afs.htm" TARGET="_mainDisplayFrame">Abstract Factory (87)</A> thatretrieves a specific Layout object with operations likeGetButtonLayout, GetMenuBarLayout, and so forth. For eachlook-and-feel standard there is a corresponding Look subclass (e.g.,MotifLook, OpenLook) that supplies the appropriate Layout objects.</P><A NAME="auto1084"></A><P>By the way, Layout objects are essentially strategies (see<A HREF="pat5ifs.htm" TARGET="_mainDisplayFrame">Strategy (315)</A>). They are an example of a strategyobject implemented as a flyweight.</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="auto1085"></A><P>The Flyweight pattern is often combined with the <A HREF="pat4cfs.htm"TARGET="_mainDisplayFrame">Composite (163)</A> pattern to implement alogically hierarchical structure in terms of a directed-acyclicgraph with shared leaf nodes.</P><A NAME="auto1086"></A><P>It's often best to implement<A HREF="pat5hfs.htm" TARGET="_mainDisplayFrame">State (305)</A> and<A HREF="pat5ifs.htm" TARGET="_mainDisplayFrame">Strategy (315)</A>objects as flyweights.</P><A NAME="last"></A><P><A HREF="#intent"><IMG SRC="gifsb/up3.gif" BORDER=0></A><BR><A HREF="pat4gfs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/rightar3.gif"	ALIGN=TOP BORDER=0></A> <A HREF="pat4gfs.htm"	TARGET="_mainDisplayFrame">Proxy</A><BR><A HREF="pat4efs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/leftarr3.gif"	ALIGN=TOP BORDER=0></A> <A HREF="pat4efs.htm"	TARGET="_mainDisplayFrame">Facade</A></P><HR><A NAME="footnote3"></A><P><SUP>3</SUP>Look-up time inthis scheme is proportional to the font change frequency.  Worst-caseperformance occurs when a font change occurs on every character, butthat's unusual in practice.</P><A NAME="footnote4"></A><P><SUP>4</SUP>In the Sample Code given earlier, style information is madeextrinsic, leaving the character code as the only intrinsic state.</P><A NAME="footnote5"></A><P><SUP>5</SUP>See <A HREF="pat3afs.htm" TARGET="_mainDisplayFrame">AbstractFactory (87)</A> for another approach to look-and-feelindependence.</P></BODY></HTML>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩一区二区电影在线| 日韩av午夜在线观看| 亚洲一区二区三区爽爽爽爽爽| 亚洲男人的天堂在线观看| 亚洲大片一区二区三区| 久久99最新地址| 国产suv一区二区三区88区| 91麻豆国产香蕉久久精品| 欧美一区二区三区视频免费 | 伊人一区二区三区| 三级成人在线视频| 成人免费看黄yyy456| 欧美日韩美少妇| 欧美国产一区二区在线观看| 亚洲一区在线视频观看| 精品在线一区二区三区| 91福利国产精品| 337p粉嫩大胆色噜噜噜噜亚洲| 亚洲欧美综合另类在线卡通| 久热成人在线视频| 一本色道久久综合狠狠躁的推荐| 日韩视频一区二区| 亚洲视频综合在线| 国产专区综合网| 欧美午夜精品久久久| 国产婷婷一区二区| 日本亚洲三级在线| 色综合一区二区三区| 精品乱码亚洲一区二区不卡| 一区二区三区日韩欧美精品| 国产精品主播直播| 这里只有精品视频在线观看| 国产精品国产三级国产三级人妇| 日韩精品一卡二卡三卡四卡无卡| 99久久er热在这里只有精品66| 91精品久久久久久久久99蜜臂| 日韩一区中文字幕| 国产成人在线视频免费播放| 欧美一区二区播放| 亚洲一区二区精品视频| 成人免费黄色大片| 2欧美一区二区三区在线观看视频 337p粉嫩大胆噜噜噜噜噜91av | 中文字幕av一区二区三区免费看| 午夜精品福利一区二区三区蜜桃| www.av精品| 日韩欧美国产精品| 午夜精品在线视频一区| 色噜噜久久综合| 欧美激情一区二区三区四区| 精品影视av免费| 91精品在线麻豆| 亚洲成人激情av| 91黄色免费观看| 最新国产成人在线观看| 国产精品123| 久久综合九色综合久久久精品综合| 天天色综合天天| 欧美精品丝袜中出| 亚洲一区二区三区在线| 91成人在线精品| 亚洲精品国产精品乱码不99| 99久久精品国产导航| 中文字幕一区在线| av亚洲精华国产精华精华| 国产日韩精品一区二区三区| 国产久卡久卡久卡久卡视频精品| 日韩精品中文字幕一区二区三区| 日本vs亚洲vs韩国一区三区 | 亚洲国产cao| 色丁香久综合在线久综合在线观看| 中文字幕一区二区日韩精品绯色| 丰满白嫩尤物一区二区| 欧美国产1区2区| 成人91在线观看| 亚洲欧美一区二区三区孕妇| av网站免费线看精品| 亚洲裸体在线观看| 欧美最新大片在线看| 亚洲一线二线三线视频| 欧美日韩一区二区三区免费看| 亚洲超碰精品一区二区| 欧美精品免费视频| 免费黄网站欧美| 2020日本不卡一区二区视频| 国产久卡久卡久卡久卡视频精品| 国产精品污网站| 91小视频免费观看| 国产色产综合色产在线视频| 国产精品综合二区| 国产精品免费看片| 91免费看视频| 亚洲va欧美va人人爽| 蜜桃视频一区二区三区在线观看| 久久99久久久久久久久久久| 日韩欧美国产1| 紧缚奴在线一区二区三区| 在线视频你懂得一区二区三区| 亚洲一二三级电影| 精品伦理精品一区| 成人av电影观看| 亚洲成人午夜电影| 2020国产精品| 在线影院国内精品| 人人超碰91尤物精品国产| 久久久久久一级片| 色悠久久久久综合欧美99| 日韩成人免费在线| 国产亚洲污的网站| 欧美性xxxxxx少妇| 狠狠狠色丁香婷婷综合久久五月| 国产精品嫩草久久久久| 欧美狂野另类xxxxoooo| 国产麻豆精品视频| 一区二区三区在线观看欧美| 欧美一区二区三区视频在线| 不卡一区在线观看| 日韩中文字幕亚洲一区二区va在线 | 国产亚洲自拍一区| 色综合久久99| 另类小说综合欧美亚洲| 亚洲色欲色欲www在线观看| 91麻豆精品国产91久久久资源速度 | 欧美在线观看一二区| 久久国内精品自在自线400部| 国产精品电影一区二区三区| 欧美日韩一区二区三区高清| 国产成人在线视频播放| 五月开心婷婷久久| 国产精品美女久久久久久久网站| 欧美日韩国产中文| 成人福利视频网站| 美国毛片一区二区| 亚洲男人的天堂在线aⅴ视频 | 岛国精品在线观看| 日韩精品一二区| 综合色天天鬼久久鬼色| 精品久久久久久久久久久久久久久| 色综合久久综合中文综合网| 韩国精品在线观看| 亚洲成人精品影院| 亚洲欧美激情插| 国产视频一区不卡| 日韩欧美一区二区不卡| 在线看不卡av| k8久久久一区二区三区| 黑人巨大精品欧美一区| 无吗不卡中文字幕| 夜夜精品浪潮av一区二区三区| 久久精品欧美一区二区三区不卡| 7777精品久久久大香线蕉| 91丨porny丨首页| 国产98色在线|日韩| 久久se精品一区精品二区| 亚洲一区二区偷拍精品| 中文字幕一区二区三| 国产日韩三级在线| 欧美成人a∨高清免费观看| 欧美亚洲图片小说| 色婷婷综合中文久久一本| 成人一区二区三区| 国产伦精品一区二区三区在线观看 | 91原创在线视频| 东方欧美亚洲色图在线| 国产一区亚洲一区| 久久精品国产99国产精品| 午夜亚洲福利老司机| 一区二区三区四区在线| 国产精品天天看| 欧美国产一区视频在线观看| 久久久久久97三级| 久久这里只有精品首页| 日韩免费高清av| 欧美一级片免费看| 91精品国产一区二区人妖| 欧美日韩成人综合在线一区二区| 在线一区二区三区四区| 色婷婷综合久久久久中文| 91在线免费播放| 91视频在线观看免费| 99久久婷婷国产综合精品电影| 国产xxx精品视频大全| 成人理论电影网| av网站一区二区三区| 色悠悠久久综合| 欧美日韩在线直播| 69堂亚洲精品首页| 日韩精品最新网址| 精品国产一二三| 国产亚洲一本大道中文在线| 国产亚洲成av人在线观看导航| 国产偷国产偷亚洲高清人白洁| 亚洲国产高清aⅴ视频| 国产精品久久久久久久久晋中 | 色噜噜狠狠成人网p站| 一本一本大道香蕉久在线精品 | 偷拍一区二区三区| 蜜乳av一区二区| 国产在线视视频有精品| 国产福利不卡视频| 色综合欧美在线视频区|