欧美色欧美亚洲高清在线观看,国产特黄特色a级在线视频,国产一区视频一区欧美,亚洲成a 人在线观看中文

  1. <ul id="fwlom"></ul>

    <object id="fwlom"></object>

    <span id="fwlom"></span><dfn id="fwlom"></dfn>

      <object id="fwlom"></object>

      設(shè)計(jì)模式-創(chuàng)建型模式的優(yōu)缺點(diǎn)比較

      時(shí)間:2019-05-15 08:36:45下載本文作者:會(huì)員上傳
      簡(jiǎn)介:寫(xiě)寫(xiě)幫文庫(kù)小編為你整理了多篇相關(guān)的《設(shè)計(jì)模式-創(chuàng)建型模式的優(yōu)缺點(diǎn)比較》,但愿對(duì)你工作學(xué)習(xí)有幫助,當(dāng)然你在寫(xiě)寫(xiě)幫文庫(kù)還可以找到更多《設(shè)計(jì)模式-創(chuàng)建型模式的優(yōu)缺點(diǎn)比較》。

      第一篇:設(shè)計(jì)模式-創(chuàng)建型模式的優(yōu)缺點(diǎn)比較

      比較幾種創(chuàng)建型模式的優(yōu)缺點(diǎn),仔細(xì)考察這幾種模式的區(qū)別和相關(guān)性。

      第一類(lèi)是工廠模式,工廠模式專(zhuān)門(mén)負(fù)責(zé)將大量有共同接口的類(lèi)實(shí)例化。工廠模式可以動(dòng)態(tài)決定將哪一個(gè)類(lèi)實(shí)例化,不必事先知道每次要實(shí)例化哪一個(gè)類(lèi)。

      工廠模式有三種形態(tài):簡(jiǎn)單工廠模式;工廠方法模式;抽象工廠模式是。前兩者是類(lèi)的創(chuàng)建模式,后者是對(duì)象的創(chuàng)建模式。

      簡(jiǎn)單工廠:

      簡(jiǎn)單工廠模式是由一個(gè)工廠類(lèi)根據(jù)傳入的參量決定創(chuàng)建出哪一種產(chǎn)品類(lèi)的實(shí)例,涉及工廠角色(Creator)、抽象產(chǎn)品(Product)角色及具體產(chǎn)品(Concrete Product)角色等三個(gè)角色。

      優(yōu)點(diǎn):

      模式的核心是工廠類(lèi),該類(lèi)中含有必要的判斷邏輯,可以決定在什么時(shí)候創(chuàng)建哪一個(gè)產(chǎn)品類(lèi)的實(shí)例,客戶端可以免除直接創(chuàng)建產(chǎn)品對(duì)象的責(zé)任,而僅僅負(fù)責(zé)“消費(fèi)”產(chǎn)品。

      簡(jiǎn)單工廠模式實(shí)現(xiàn)了對(duì)責(zé)任的分割。

      缺點(diǎn):

      當(dāng)產(chǎn)品類(lèi)有復(fù)雜的多層次等級(jí)結(jié)構(gòu)時(shí),工廠類(lèi)只有它自己。

      模式中工廠類(lèi)集中了所有的產(chǎn)品創(chuàng)建邏輯,形成一個(gè)無(wú)所不知的全能類(lèi)。

      將多個(gè)創(chuàng)建邏輯放在一個(gè)類(lèi)中,當(dāng)產(chǎn)品類(lèi)有不同接口種類(lèi)時(shí),工廠類(lèi)需要判斷在什么時(shí)候創(chuàng)建某種產(chǎn)品,使得系統(tǒng)在將來(lái)進(jìn)行功能擴(kuò)展時(shí)較為困難。

      該模式采用靜態(tài)方法作為工廠方法,而靜態(tài)方法無(wú)法由子類(lèi)繼承,因此工廠角色無(wú)法形成基于繼承的等級(jí)結(jié)構(gòu)。

      簡(jiǎn)單工廠模式只在有限的程度上符合“開(kāi)-閉”原則。

      工廠方法:

      定義一個(gè)用于創(chuàng)建對(duì)象的接口,讓子類(lèi)決定實(shí)例化哪一個(gè)類(lèi)。Factory Method使一個(gè)類(lèi)的實(shí)例化延遲到其子類(lèi)。工廠方法模式是簡(jiǎn)單工廠模式的進(jìn)一步抽象和推廣,其基本思想是定義一個(gè)創(chuàng)建產(chǎn)品對(duì)象的工廠接口,將實(shí)際創(chuàng)建工作推遲到子類(lèi)中。

      優(yōu)點(diǎn):

      多態(tài)性:客戶代碼可以做到與特定應(yīng)用無(wú)關(guān),適用于任何實(shí)體類(lèi)

      子類(lèi)可以重寫(xiě)新的實(shí)現(xiàn),也可以繼承父類(lèi)的實(shí)現(xiàn)。加一層間接性,增加了靈活性。良好的封裝性,代碼結(jié)構(gòu)清晰。擴(kuò)展性好,在增加產(chǎn)品類(lèi)的情況下,只需要適當(dāng)修改具體的工廠類(lèi)或擴(kuò)展一個(gè)工廠類(lèi),就可“擁抱變化”屏蔽產(chǎn)品類(lèi)。產(chǎn)品類(lèi)的實(shí)現(xiàn)如何變化,調(diào)用者都不需要關(guān)心,只需關(guān)心產(chǎn)品的接口,只要接口保持不變,系統(tǒng)中的上層模塊就不會(huì)發(fā)生變化。

      典型的解耦框架。高層模塊只需要知道產(chǎn)品的抽象類(lèi),其他的實(shí)現(xiàn)類(lèi)都不需要關(guān)心,符合迪米特法則,符合依賴(lài)倒置原則,符合里氏替換原則。

      缺點(diǎn): 需要Creator和相應(yīng)的子類(lèi)作為工廠方法的載體,如果應(yīng)用模型確實(shí)需要creator和子類(lèi)存在,則很好;否則的話,需要增加一個(gè)類(lèi)層次。

      抽象工廠:

      提供一個(gè)創(chuàng)建一系列相關(guān)或相互依賴(lài)對(duì)象的接口,而無(wú)需指定它們具體的類(lèi),客戶端不必指定產(chǎn)品的具體類(lèi)型,創(chuàng)建多個(gè)產(chǎn)品族中的產(chǎn)品對(duì)象。

      優(yōu)點(diǎn):

      分離了具體的類(lèi),一個(gè)工廠封裝創(chuàng)建產(chǎn)品對(duì)象的責(zé)任和過(guò)程,它將客戶與類(lèi)的實(shí)現(xiàn)分離易于交換產(chǎn)品系列,只需改變具體的工廠就可以使用不同的產(chǎn)品配置。

      有利于產(chǎn)品的一致性,當(dāng)一個(gè)系列中的產(chǎn)品對(duì)象被設(shè)計(jì)成一起工作時(shí),一個(gè)應(yīng)用一次只能使用同一個(gè)系列中的對(duì)象。

      缺點(diǎn):

      難以支持新的產(chǎn)品等級(jí)結(jié)構(gòu),支持新的產(chǎn)品等級(jí)結(jié)構(gòu)就要擴(kuò)展抽象工廠接口。

      單例模式:

      一個(gè)類(lèi)僅有一個(gè)實(shí)例,自行實(shí)例化并向整個(gè)系統(tǒng)提供一個(gè)訪問(wèn)它的全局訪問(wèn)點(diǎn)。確保一個(gè)類(lèi)只能被實(shí)例化一次。

      優(yōu)點(diǎn): 跨平臺(tái):使用合適的中間件,可以把singleton模式擴(kuò)展為跨多個(gè)JVM和多個(gè)計(jì)算機(jī)工作。適用于任何類(lèi):只需把一個(gè)類(lèi)的構(gòu)造函數(shù)變成私有的,并且在其中增加相應(yīng)的靜態(tài)函數(shù)和變量,就可以把這個(gè)類(lèi)變?yōu)閟ingleton。

      可以通過(guò)派生創(chuàng)建:給定一個(gè)類(lèi),可以創(chuàng)建它的一個(gè)singleton子類(lèi)。

      延遲求值:如果singleton從未使用過(guò),那么就絕不會(huì)創(chuàng)建它。

      缺點(diǎn):

      摧毀方法未定義: 沒(méi)有好的方法去摧毀一個(gè)singleton,或者解除其責(zé)任。

      不能繼承:從singleton派生的類(lèi)并不是singleton。如果要使其成為singleton,必須要增加所需的靜態(tài)函數(shù)和變量。

      效率問(wèn)題:每次調(diào)用instance方法都會(huì)執(zhí)行if語(yǔ)句,多余。

      不透明性: singleton的使用者知道它們正在使用一個(gè)singleton,因?yàn)樗鼈儽仨氁{(diào)用instance方法。

      建造者模式:

      將一個(gè)復(fù)雜對(duì)象的構(gòu)建與它的表示分離,使得同樣的構(gòu)建過(guò)程可以創(chuàng)建不同的表示。建造模式利用一個(gè)導(dǎo)演者對(duì)象和具體建造者對(duì)象一個(gè)一個(gè)地建造出所有的零件,從而建造出完整的對(duì)象。

      優(yōu)點(diǎn): 建造模式的使用使得產(chǎn)品的內(nèi)部表象可以獨(dú)立地變化。使用建造模式可以使客戶端不必知道產(chǎn)品內(nèi)部組成的細(xì)節(jié)。

      每一個(gè)Builder都相對(duì)獨(dú)立,而與其他的Builder無(wú)關(guān)。模式所建造的最終產(chǎn)品更易于控制。

      缺點(diǎn):

      建造者模式的“加工工藝”是暴露的,這樣使得建造者模式更加靈活,也使得工藝變得對(duì)客戶不透明。

      原型模式:

      用原型實(shí)例指定創(chuàng)建對(duì)象的種類(lèi),并且通過(guò)拷貝這些原型創(chuàng)建新的對(duì)象。以一個(gè)已有的對(duì)象作為原型,通過(guò)它來(lái)創(chuàng)建新的對(duì)象。在增加新的對(duì)象的時(shí)候,新對(duì)象的細(xì)節(jié)創(chuàng)建工作由自己來(lái)負(fù)責(zé),從而使新對(duì)象的創(chuàng)建過(guò)程與框架隔離開(kāi)來(lái)。

      優(yōu)點(diǎn):

      原型模式允許動(dòng)態(tài)地增加或減少產(chǎn)品類(lèi)。由于創(chuàng)建產(chǎn)品類(lèi)實(shí)例的方法是產(chǎn)品類(lèi)內(nèi)部具有的,因此增加新產(chǎn)品對(duì)整個(gè)結(jié)構(gòu)沒(méi)有影響。

      原型模式提供簡(jiǎn)化的創(chuàng)建結(jié)構(gòu)。工廠方法常需要有一個(gè)與產(chǎn)品類(lèi)相同的等級(jí)結(jié)構(gòu),而原型模式不需要。

      具有給一個(gè)應(yīng)用軟件加載新功能的能力。

      產(chǎn)品類(lèi)不需要非得有任何事先確定的等級(jí)結(jié)構(gòu),因?yàn)樵湍J竭m用于任何的等級(jí)結(jié)構(gòu)。

      缺點(diǎn):

      每一個(gè)類(lèi)必須配備一個(gè)克隆方法。

      配備克隆方法需要對(duì)類(lèi)的功能進(jìn)行通盤(pán)考慮,這對(duì)于全新的類(lèi)不是很難,但對(duì)于已有的類(lèi)不一定很容易,特別當(dāng)一個(gè)類(lèi)引用不支持串行化的間接對(duì)象,或者引用含有循環(huán)結(jié)構(gòu)的時(shí)候。

      關(guān)系總結(jié): 工廠方法模式是簡(jiǎn)單工廠模式的擴(kuò)展,由于使用了多態(tài)性,工廠方法模式保持了簡(jiǎn)單工廠模式的優(yōu)點(diǎn),而且克服了它的缺點(diǎn)。如果只有一個(gè)具體工廠類(lèi),工廠方法模式可以改造為簡(jiǎn)單工廠模式。抽象工廠經(jīng)常用工廠方法來(lái)實(shí)現(xiàn)。Prototype:不需要?jiǎng)?chuàng)建Creator的子類(lèi),但它們通常需要一個(gè)針對(duì)Product類(lèi)的Initialize操作。抽象工廠模式是對(duì)象的創(chuàng)建模式,是工廠方法模式的進(jìn)一步推廣。抽象工廠模式是所有形態(tài)的工廠模式中最為抽象和最具一般性的一種形態(tài)。工廠方法模式針對(duì)的是一個(gè)產(chǎn)品等級(jí)結(jié)構(gòu);抽象工廠模式需要面對(duì)多個(gè)產(chǎn)品等級(jí)結(jié)構(gòu)。Singleton與其他創(chuàng)建型模式并不矛盾,可以用Singleton來(lái)實(shí)現(xiàn)其他模式中的對(duì)象。包括Abstract Factory、Builder、Prototype等。Builder和Abstract Factory都可以創(chuàng)建復(fù)雜的對(duì)象。但是Builder模式著重于一步步構(gòu)造一個(gè)復(fù)雜的對(duì)象,強(qiáng)調(diào)的是產(chǎn)品的內(nèi)部組成,Abstract factory著重于多個(gè)系列的產(chǎn)品對(duì)象。Builder在最后一步返回產(chǎn)品,而Abstract factory立即返回產(chǎn)品。

      Abstractor Factory處于更為具體的角度,Builder處于更宏觀的角度。一個(gè)系統(tǒng)可以由一個(gè)建造模式和一個(gè)抽象工廠模式組成,客戶端通過(guò)調(diào)用這個(gè)建造模式,間接地調(diào)用另一個(gè)抽象工廠模式的工廠角色。工廠模式返還不同產(chǎn)品族的零件,而建造模式把它們組裝起來(lái)。8 Prototype和Abstract factory往往是競(jìng)爭(zhēng)的關(guān)系,但是它們也可以一起使用。抽象工廠可以存儲(chǔ)一個(gè)被克隆的原型的集合,并返回產(chǎn)品的對(duì)象。

      第二篇:模式比較

      玫琳凱模式---顧問(wèn)交友式

      1.皮膚分析卡 預(yù)約:了解基本信息、提前準(zhǔn)備課前:了解皮膚問(wèn)題,了解需求點(diǎn)課后:滿足需求、強(qiáng)化需求

      2.美容課講義夾

      講文化、企業(yè):對(duì)公司認(rèn)同、文化認(rèn)同講皮膚知識(shí):打造專(zhuān)業(yè)形象

      規(guī)范護(hù)膚步驟:強(qiáng)化需求、專(zhuān)業(yè)信服產(chǎn)品試用: 親身體驗(yàn) 滿足需求

      結(jié)束報(bào)價(jià):讓情感上接受、心中有數(shù)促銷(xiāo)快報(bào):物超所值 達(dá)成銷(xiāo)售

      女主人禮物展示:達(dá)成延伸和刺激分享

      3.售后服務(wù)送貨上門(mén),打開(kāi)試用,規(guī)范護(hù)膚步驟:拉近距離針對(duì)全面需求給予全套護(hù)理流程:

      完整的護(hù)膚步驟和建議、專(zhuān)業(yè)和規(guī)范講解讓人信服、貼心服務(wù)逐步解決顧客需求,有專(zhuān)業(yè)的解決方案

      了解喜好、邀約相關(guān)活動(dòng)、了解他周?chē)娜耍屗蔀榕魅?、邀約更多人、用她的分享帶動(dòng)銷(xiāo)售

      4.事業(yè)機(jī)會(huì)手冊(cè):針對(duì)不同需求有不同版本的事業(yè)機(jī)會(huì)分享,有針對(duì)性的感情投入,既能成為優(yōu)質(zhì)的主顧,也能有機(jī)會(huì)成為事業(yè)機(jī)會(huì)的合作者。

      保險(xiǎn)改進(jìn)模式-------專(zhuān)業(yè)理財(cái)顧問(wèn)

      1.預(yù)約:了解基本財(cái)務(wù)狀況

      授前:了解財(cái)務(wù)困惑、了解需求點(diǎn)授中:強(qiáng)化需求、滿足需求 2.理財(cái)課堂 講輕松氛圍講文化、企業(yè)

      講理財(cái)重要、基本理財(cái)工具運(yùn)用講家庭理財(cái)組合(4321)講保險(xiǎn)意義與功用

      3.售后服務(wù)強(qiáng)化理財(cái)理念,投資組合意識(shí)給予資產(chǎn)分類(lèi)管理方案對(duì)每種方案的注意事項(xiàng)

      對(duì)家庭成員完整的保險(xiǎn)計(jì)劃

      理賠會(huì)出現(xiàn)的問(wèn)題,給予對(duì)應(yīng)的解決方案

      保險(xiǎn)個(gè)人銷(xiāo)售行為-----------專(zhuān)業(yè)個(gè)人理財(cái)規(guī)劃師 從賣(mài)保險(xiǎn)-------銷(xiāo)售理財(cái)計(jì)劃

      對(duì)立的關(guān)系---------依賴(lài)信任的關(guān)系根本是解決問(wèn)題的能力、讓他成為你滿意的顧客讓他的分享給你帶來(lái)源源不斷地利潤(rùn),所以情感投入,全身心的售前、售后專(zhuān)業(yè)全面的服務(wù)才是贏得客戶心的唯一途徑,這樣保險(xiǎn)的營(yíng)銷(xiāo)就 不成問(wèn)題。

      關(guān)鍵在于專(zhuān)業(yè)

      第三篇:英文寫(xiě)作---比較型說(shuō)明文的模式

      比較型說(shuō)明文的模式

      第一步:審題

      1.A Major Advantage or Disadvantage of Playing Computer Games

      2.The Advantages and Disadvantages of Air Travel

      3.Some people believe that a college or university education should be available toall students;others believe that higher education should be available only to goodstudents.What’s your opinion?

      第二步:構(gòu)思

      模式

      I(該模式用于比較兩個(gè)事物,作者的傾向比較明顯時(shí))

      第一段, 引言句(現(xiàn)象或事實(shí)陳述法)引出要比較的兩個(gè)事物

      (A 或B)用一句話表明自己的觀點(diǎn)(如:傾向A)

      第二段, 段落主題句承接首段中的觀點(diǎn),并對(duì)本段內(nèi)容加以限定

      比較之一:

      指出A事物的優(yōu)點(diǎn)之一, 用拓展句加以說(shuō)明.通過(guò)轉(zhuǎn)折指出B事物的缺點(diǎn), 用拓展句加以說(shuō)明.比較之二:

      指出A事物的優(yōu)點(diǎn)之二, 用拓展句加以說(shuō)明.通過(guò)轉(zhuǎn)折指出B事物的缺點(diǎn),用拓展句加以說(shuō)明.(A1B1A2B2A3B3 point-by-point pattern)

      第三段, 得出結(jié)論,注意首尾觀點(diǎn)一致.Television As a Better Source of NewsAmong the three mass media—television, newspaper and radio, I regard television as a better source.My statement that television is a better source of news is based on the following two reasons.The first reason is that television can report news more quickly.We can get the news at the same time when something is happening or immediately after something happened.While newspapers can only offer the news that happened a day or two days ago.The second reason is that television can report news more vividly and impressively.With sounds and pictures on TV, we can be deeply impressed by the news as if we were personally on the spot.But when we try to get news from the newspaper, we have to concentrate our mind on the lines and use our imaginations to for a concrete image, which is always tiresome and time-consuming.According to the above mentioned reasons;we can easily draw a conclusion that television is really a better source of news.模式II

      如果作文要求比較兩個(gè)事物的不同之處,宜用下列結(jié)構(gòu):

      第一段, 引言句(一般用現(xiàn)象陳述法,提問(wèn))引出要比較的兩個(gè);主題句指出的兩個(gè)事物存在著明顯的差異或兩個(gè)事物的不同特點(diǎn).第二段, 直接評(píng)述A事物的主要特點(diǎn),用拓展句加以說(shuō)明(舉例,一般闡述);指出B事物的主要特點(diǎn),用拓展句加以具體明.(A1A2A3B1B2B3

      subject-by-subject pattern)

      第三段, 通過(guò)比較得出傾向性的結(jié)論, 表明作者的態(tài)度.Where to Live–in the City or the Country

      Many people appreciate the conveniences of the city.The city has better transportation service and health care.City dwellers can easily enjoy themselves in restaurants, department stores and concert halls.They are well-informed about what is going on at home and abroad, and have the access to better education, better jobs and more opportunities for business.But country life is also attractive.With the fresh air, the green trees and the singing birds, country people are close to nature and live a quiet life.They can make friends with simple and honest men or wander about leisurely without any pressure upon their mind.Both the country and the city, however, have their own disadvantages.In the country, educational facilities, medical services and transportation systems are still not fully developed.And the city also has many problems, such as heavy traffic, air pollution, great noise and poor housing conditions.As far as I’m concerned, I hated the terrible dirt and noise in the city.So, given the chance, I would prefer to live peacefully in the country.The Main Difference Between Exam-oriented Education and Quality-oriented Education

      Education in China used to be exam-oriented one.But with the development of education reform, quality-oriented education is stressed again and again.So there rises a question: what is the main difference between these two?

      Accordingto my understanding, exam-oriented education focuses on students’ ability of passing examination of different levels.This education is to test the students command of knowledge they

      have obtained from the textbooks.So examination results are the only criterion which is used to evaluate the students whether they are “excellent” ones or “bad” ones.However, quality-oriented

      education focuses on students’ various qualities, including academic moral quality, cultural quality, most important, their individual personality and potentialities.The main purpose of this education is to bring students’ practical potentialities into full play.Quality-oriented education can teach students how to face difficulties and solve problems independently.From the above comparison between exam-oriented education and quality-oriented education, we find that the latter one is superior.So it is time for our universities and colleges to bring quality-oriented education into students’ daily life.比較一個(gè)事物的兩個(gè)方面的時(shí)候也可以用這種模式:

      第一段, 引言句引出要比較的兩個(gè)方面(advantage & disadvantage)

      第二段, 直接評(píng)述advantage,用拓展句加以說(shuō)明(舉例,一般闡述);然后再指出disadvantage,用拓展句加以具體明.(A1A2A3B1B2B3 subject-by-subject pattern)

      第三段, 通過(guò)比較得出傾向性的結(jié)論, 表明優(yōu)劣或作者態(tài)度.The Advantages and Disadvantages of Air Travel

      In the last fifty years, traveling by air has become the most popular form of long-distance journeys.However, there are both positive and negative associated with it.The first advantage of air travel is that it is quick.For instance, we can fly from Beijing to Guangzhou in less than three hours.The second advantage of traveling by air is that it is convenient.After we have checked in, all we have to do is to get on and sit down.The friendly air stewardess will look after our every need.The third advantage of traveling by air is that it is now relatively cheep, especially for long distance travel.We can fly from Beijing to Guangzhou for only 1200 Yuan.But on the other hand, traveling by air has its disadvantages.Perhaps the most obvious is the element of danger involved, such as hijackings and crashes.Traveling by air also makes it impossible for us to see many scenic spot on the way to our destination.In addition to the above mentioned, a long distance air travel may make us very tired, both mentally and physically.Many precious days of holiday may be wasted recovering from airsickness.To conclude, although air travel involves inconvenience and slight risk, I would say that the advantages mentioned above weigh much more than the disadvantages.Exercise:

      With the development of computer, the Internet has become widely used.It is just like information net that has covered the world.Some people worry that it provides too much for people.Write a composition of about 200 words to state your view on this issue.Does the Internet Provide Too Much for People

      When a great deal of information is exchanged on the Internet almost every second, some people worry that it provides too much for people.To know it clearly, we should look at both sides of the Internet.On one hand, the Internet shows us a closer and wider world than ever before.Just staying at home, we can get all kinds of useful information in any scientific research field whenever we need.Through the Internet, more and more chances are provided to improve our work, enrich our knowledge and help our country to keep up with the others.But on the other hand, the Internet also brings us many troubles.Useless information and games send to us unavoidably.From this angle, we have to say that those people’s complaints are understandable.Generally speaking, the Internet has played an important role in modern life.It is like a double-edged sword.We should make the best use of one edge, and try not to be hurt by the other one.模式III

      (該模式用于比較兩個(gè)事物時(shí)作者的傾向比較明顯)

      第一段, 引言句引出要比較的兩個(gè)事物;主題句概括地指出其中一個(gè)事物的優(yōu)點(diǎn)和缺點(diǎn)。

      (傾向于A)

      第二段, 只評(píng)述A事物的優(yōu)點(diǎn),用拓展句加以說(shuō)明(舉例,一般闡述);指出A事物的缺點(diǎn),用拓展句加以具體明.第三段, 通過(guò)比較得出傾向性的結(jié)論, 表明作者的態(tài)度.這樣類(lèi)似于比較一個(gè)事物的兩個(gè)方面。

      Sharing a Room with a Stranger or Living by Yourself

      Nowadays, more and more college students like to live off campus.Some prefer to share a flat with somebody else to divide the rent between them and others prefer to have a flat to themselves.There are always two aspects to one situation.Sharing a flat with somebody else has its advantages and disadvantages.Study requires peace and quietness.A stranger who shares a room with you may disturb you.Your thoughts can be interrupted by his sudden return, or by asking for a light, or merely by his cough or sneeze.At night, when you want to sleep, he may be tossing in bed, making enough noise to keep you awake.If the stranger is bad-tempered, he may quarrel with you, and yet, you must have patience.However, there are many positive aspects of sharing a room with a stranger.First, with another person in the room, you will not feel lonely although far way from you home.Second, you can always help each other.Whatever difficulty you are in, you can get a helping hand.If the person you live with is a senior student, you can even get advice from him on your work and study.Third, living with a stranger offers you a chance of learning to get along with people.Since you have to live with a stranger for quite a long period, you will do your best to make friends with him.If you are successful in gaining his trust, you may also be successful in the more complicated and competitive society.Therefore, I think, sharing a room with a stranger is a good arrangement of living for all the disadvantages.I prefer to share a flat with someone else rather than live alone.Where to Live– in the City or in the Country

      Each year thousands of people rush into big cities.Some come for education, some for shopping and some on business.But most of them, attracted by the job opportunities and modern life, come to stay.People enjoy city life chiefly for its conveniences.To begin with, the city provides fast transport, with roads and buses leading to every corner.Then, there are department stores and shops all over the city, where you can buy all kinds of goods you want.Besides, hospitals and other services are

      all within easy reach.Indeed, whatever your need is, you can easily get what your want.However, ig cities are confronted with many problems.One is the housing problem.For examples, it is not uncommon for two or even three generations to share an apartment.Another problem is pollution.The air is not clean and the environment is noisy.In short, the city is only a place for business, to be visited occasionally.It is not an

      ideal place for permanent living.模式IV

      第一段, 引言句引出要比較的兩個(gè)事物;主題句鮮明地表明作者的態(tài)度—傾向其中一個(gè)(如:

      A)。

      第二段, 只評(píng)述A事物的優(yōu)點(diǎn),用拓展句加以說(shuō)明(舉例,一般闡述)

      第三段, 總結(jié)A的優(yōu)點(diǎn),再次表明態(tài)度,和第一段里態(tài)度一致。

      這種方式就將比較型的說(shuō)明文變成了闡述型的說(shuō)明文。

      Where to Live– in the City or in the Country

      There are undeniable advantages to both life in a big city and in a small town.However, despite the advantages of small town life, I prefer to live in a big city for several reasons.First, life in the big city is more convenient.More goods are available and stores stay open later.Also, there is better public transportation, so it is easier to get around.I can find almost anything I want easily in the city.Second, there are more ways to spend leisure time in the city.There are many places I can go to meet friends and have fun.Finally, and most importantly, the city offers more educational and job opportunities.The city often attracts the best teachers and the best companies.There is also a wider choice of jobs so it is easier to move up the career ladder.For all these reasons, I prefer to live in the city.Although I sometimes miss the fresh air and quiet life of a small town, nothing can make up for the opportunities that the city offers.Exercise:

      Some people believe that a college or university education should be available to all students;others believe that higher education should be available only to good students.What’s your opinion?

      Opening University Doors to All Students

      Some people believe that university education should be available to all students.Others believe that higher education should be limited to only good students.I think universities should open their doors to all students.Those who argue for the availability of university education to good students think that having only good students study in university would save the government’s fund.However, these people neglect one fact that most school graduates are too young to work.These young people, especially the so-called bad students, since they are refused by colleges and universities, have nothing to do and would easily form gangs.Those who argue for the availability of higher education to all students believe that every student should have the equal right to education.Besides, when mass students have university education year after year, the education lever of the whole society will finally get promoted, resulting in a better quality of the nation.Apparently, opening university doors to all students benefits the society and

      the whole nation;therefore, it is a better choice for us to take.

      第四篇:JAVA設(shè)計(jì)模式之創(chuàng)建模式

      設(shè)計(jì)模式之Builder

      Builder模式定義: 將一個(gè)復(fù)雜對(duì)象的構(gòu)建與它的表示分離,使得同樣的構(gòu)建過(guò)程可以創(chuàng)建不同的表示.Builder模式是一步一步創(chuàng)建一個(gè)復(fù)雜的對(duì)象,它允許用戶可以只通過(guò)指定復(fù)雜對(duì)象的類(lèi)型和內(nèi)容就可以構(gòu)建它們.用戶不知道內(nèi)部的具體構(gòu)建細(xì)節(jié).Builder模式是非常類(lèi)似抽象工廠模式,細(xì)微的區(qū)別大概只有在反復(fù)使用中才能體會(huì)到.為何使用?

      是為了將構(gòu)建復(fù)雜對(duì)象的過(guò)程和它的部件解耦.注意: 是解耦過(guò)程和部件.因?yàn)橐粋€(gè)復(fù)雜的對(duì)象,不但有很多大量組成部分,如汽車(chē),有很多部件:車(chē)輪 方向盤(pán) 發(fā)動(dòng)機(jī)還有各種小零件等等,部件很多,但遠(yuǎn)不止這些,如何將這些部件裝配成一輛汽車(chē),這個(gè)裝配過(guò)程也很復(fù)雜(需要很好的組裝技術(shù)),Builder模式就是為了將部件和組裝過(guò)程分開(kāi).如何使用?

      首先假設(shè)一個(gè)復(fù)雜對(duì)象是由多個(gè)部件組成的,Builder模式是把復(fù)雜對(duì)象的創(chuàng)建和部件的創(chuàng)建分別開(kāi)來(lái),分別用Builder類(lèi)和Director類(lèi)來(lái)表示.首先,需要一個(gè)接口,它定義如何創(chuàng)建復(fù)雜對(duì)象的各個(gè)部件: public interface Builder {

      //創(chuàng)建部件A 比如創(chuàng)建汽車(chē)車(chē)輪

      void buildPartA();

      //創(chuàng)建部件B 比如創(chuàng)建汽車(chē)方向盤(pán)

      void buildPartB();

      //創(chuàng)建部件C 比如創(chuàng)建汽車(chē)發(fā)動(dòng)機(jī)

      void buildPartC();

      //返回最后組裝成品結(jié)果(返回最后裝配好的汽車(chē))

      //成品的組裝過(guò)程不在這里進(jìn)行,而是轉(zhuǎn)移到下面的Director類(lèi)中進(jìn)行.//從而實(shí)現(xiàn)了解耦過(guò)程和部件

      Product getResult();} 用Director構(gòu)建最后的復(fù)雜對(duì)象,而在上面Builder接口中封裝的是如何創(chuàng)建一個(gè)個(gè)部件(復(fù)雜對(duì)象是由這些部件組成的),也就是說(shuō)Director的內(nèi)容是如何將部件最后組裝成成品: public class Director {

      private Builder builder;

      public Director(Builder builder){

      this.builder = builder;} // 將部件partA partB partC最后組成復(fù)雜對(duì)象 //這里是將車(chē)輪 方向盤(pán)和發(fā)動(dòng)機(jī)組裝成汽車(chē)的過(guò)程 public void construct(){

      builder.buildPartA();

      builder.buildPartB();

      builder.buildPartC();

      } } Builder的具體實(shí)現(xiàn)ConcreteBuilder: 通過(guò)具體完成接口Builder來(lái)構(gòu)建或裝配產(chǎn)品的部件;定義并明確它所要?jiǎng)?chuàng)建的是什么具體東西;提供一個(gè)可以重新獲取產(chǎn)品的接口: public class ConcreteBuilder implements Builder {

      Part partA, partB, partC;public void buildPartA(){

      //這里是具體如何構(gòu)建partA的代碼

      };public void buildPartB(){

      //這里是具體如何構(gòu)建partB的代碼 };public void buildPartC(){

      //這里是具體如何構(gòu)建partB的代碼 };public Product getResult(){

      //返回最后組裝成品結(jié)果 };} 復(fù)雜對(duì)象:產(chǎn)品Product: public interface Product { } 復(fù)雜對(duì)象的部件: public interface Part { }

      我們看看如何調(diào)用Builder模式: ConcreteBuilder builder = new ConcreteBuilder();Director director = new Director(builder);

      director.construct();Product product = builder.getResult();Builder模式的應(yīng)用

      在Java實(shí)際使用中,我們經(jīng)常用到“池”(Pool)的概念,當(dāng)資源提供者無(wú)法提供足夠的資源,并且這些資源需要被很多用戶反復(fù)共享時(shí),就需要使用池.“池”實(shí)際是一段內(nèi)存,當(dāng)池中有一些復(fù)雜的資源的“斷肢”(比如數(shù)據(jù)庫(kù)的連接池,也許有時(shí)一個(gè)連接會(huì)中斷),如果循環(huán)再利用這些“斷肢”,將提高內(nèi)存使用效率,提高池的性能.修改Builder模式中Director類(lèi)使之能診斷“斷肢”斷在哪個(gè)部件上,再修復(fù)這個(gè)部件.設(shè)計(jì)模式之Factory

      定義:提供創(chuàng)建對(duì)象的接口.為何使用?

      工廠模式是我們最常用的模式了,著名的Jive論壇 ,就大量使用了工廠模式,工廠模式在Java程序系統(tǒng)可以說(shuō)是隨處可見(jiàn)。

      為什么工廠模式是如此常用?因?yàn)楣S模式就相當(dāng)于創(chuàng)建實(shí)例對(duì)象的new,我們經(jīng)常要根據(jù)類(lèi)Class生成實(shí)例對(duì)象,如A a=new A()工廠模式也是用來(lái)創(chuàng)建實(shí)例對(duì)象的,所以以后new時(shí)就要多個(gè)心眼,是否可以考慮實(shí)用工廠模式,雖然這樣做,可能多做一些工作,但會(huì)給你系統(tǒng)帶來(lái)更大的可擴(kuò)展性和盡量少的修改量。我們以類(lèi)Sample為例,如果我們要?jiǎng)?chuàng)建Sample的實(shí)例對(duì)象: Sample sample=new Sample();可是,實(shí)際情況是,通常我們都要在創(chuàng)建sample實(shí)例時(shí)做點(diǎn)初始化的工作,比如賦值 查詢(xún)數(shù)據(jù)庫(kù)等。

      首先,我們想到的是,可以使用Sample的構(gòu)造函數(shù),這樣生成實(shí)例就寫(xiě)成: Sample sample=new Sample(參數(shù));但是,如果創(chuàng)建sample實(shí)例時(shí)所做的初始化工作不是象賦值這樣簡(jiǎn)單的事,可能是很長(zhǎng)一段代碼,如果也寫(xiě)入構(gòu)造函數(shù)中,那你的代碼很難看了(就需要Refactor重整)。為什么說(shuō)代碼很難看,初學(xué)者可能沒(méi)有這種感覺(jué),我們分析如下,初始化工作如果是很長(zhǎng)一段代碼,說(shuō)明要做的工作很多,將很多工作裝入一個(gè)方法中,相當(dāng)于將很多雞蛋放在一個(gè)籃子里,是很危險(xiǎn)的,這也是有背于Java面向?qū)ο蟮脑瓌t,面向?qū)ο蟮姆庋b(Encapsulation)和分派(Delegation)告訴我們,盡量將長(zhǎng)的代碼分派“切割”成每段,將每段再“封裝”起來(lái)(減少段和段之間偶合聯(lián)系性),這樣,就會(huì)將風(fēng)險(xiǎn)分散,以后如果需要修改,只要更改每段,不會(huì)再發(fā)生牽一動(dòng)百的事情。

      在本例中,首先,我們需要將創(chuàng)建實(shí)例的工作與使用實(shí)例的工作分開(kāi), 也就是說(shuō),讓創(chuàng)建實(shí)例所需要的大量初始化工作從Sample的構(gòu)造函數(shù)中分離出去。

      這時(shí)我們就需要Factory工廠模式來(lái)生成對(duì)象了,不能再用上面簡(jiǎn)單new Sample(參數(shù))。還有,如果Sample有個(gè)繼承如MySample, 按照面向接口編程,我們需要將Sample抽象成一個(gè)接口.現(xiàn)在Sample是接口,有兩個(gè)子類(lèi)MySample 和HisSample.我們要實(shí)例化他們時(shí),如下: Sample mysample=new MySample();Sample hissample=new HisSample();隨著項(xiàng)目的深入,Sample可能還會(huì)“生出很多兒子出來(lái)”, 那么我們要對(duì)這些兒子一個(gè)個(gè)實(shí)例化,更糟糕的是,可能還要對(duì)以前的代碼進(jìn)行修改:加入后來(lái)生出兒子的實(shí)例.這在傳統(tǒng)程序中是無(wú)法避免的.但如果你一開(kāi)始就有意識(shí)使用了工廠模式,這些麻煩就沒(méi)有了.工廠方法

      你會(huì)建立一個(gè)專(zhuān)門(mén)生產(chǎn)Sample實(shí)例的工廠: public class Factory{

      public static Sample creator(int which){

      //getClass 產(chǎn)生Sample 一般可使用動(dòng)態(tài)類(lèi)裝載裝入類(lèi)。if(which==1)

      return new SampleA();else if(which==2)

      return new SampleB();

      } } 那么在你的程序中,如果要實(shí)例化Sample時(shí).就使用 Sample sampleA=Factory.creator(1);這樣,在整個(gè)就不涉及到Sample的具體子類(lèi),達(dá)到封裝效果,也就減少錯(cuò)誤修改的機(jī)會(huì),這個(gè)原理可以用很通俗的話來(lái)比喻:就是具體事情做得越多,越容易范錯(cuò)誤.這每個(gè)做過(guò)具體工作的人都深有體會(huì),相反,官做得越高,說(shuō)出的話越抽象越籠統(tǒng),范錯(cuò)誤可能性就越少.好象我們從編程序中也能悟出人生道理?呵呵.使用工廠方法 要注意幾個(gè)角色,首先你要定義產(chǎn)品接口,如上面的Sample,產(chǎn)品接口下有Sample接口的實(shí)現(xiàn)類(lèi),如SampleA,其次要有一個(gè)factory類(lèi),用來(lái)生成產(chǎn)品Sample,如下圖,最右邊是生產(chǎn)的對(duì)象Sample:

      進(jìn)一步稍微復(fù)雜一點(diǎn),就是在工廠類(lèi)上進(jìn)行拓展,工廠類(lèi)也有繼承它的實(shí)現(xiàn)類(lèi)concreteFactory了。抽象工廠

      工廠模式中有: 工廠方法(Factory Method)抽象工廠(Abstract Factory).這兩個(gè)模式區(qū)別在于需要?jiǎng)?chuàng)建對(duì)象的復(fù)雜程度上。如果我們創(chuàng)建對(duì)象的方法變得復(fù)雜了,如上面工廠方法中是創(chuàng)建一個(gè)對(duì)象Sample,如果我們還有新的產(chǎn)品接口Sample2.這里假設(shè):Sample有兩個(gè)concrete類(lèi)SampleA和SamleB,而Sample2也有兩個(gè)concrete類(lèi)Sample2A和SampleB2 那么,我們就將上例中Factory變成抽象類(lèi),將共同部分封裝在抽象類(lèi)中,不同部分使用子類(lèi)實(shí)現(xiàn),下面就是將上例中的Factory拓展成抽象工廠: public abstract class Factory{

      public abstract Sample creator();

      public abstract Sample2 creator(String name);} public class SimpleFactory extends Factory{

      public Sample creator(){

      .........return new SampleA } public Sample2 creator(String name){

      .........return new Sample2A } } public class BombFactory extends Factory{

      public Sample creator(){

      ......return new SampleB } public Sample2 creator(String name){

      ......return new Sample2B } }

      從上面看到兩個(gè)工廠各自生產(chǎn)出一套Sample和Sample2,也許你會(huì)疑問(wèn),為什么我不可以使用兩個(gè)工廠方法來(lái)分別生產(chǎn)Sample和Sample2? 抽象工廠還有另外一個(gè)關(guān)鍵要點(diǎn),是因?yàn)?SimpleFactory內(nèi),生產(chǎn)Sample和生產(chǎn)Sample2的方法之間有一定聯(lián)系,所以才要將這兩個(gè)方法捆綁在一個(gè)類(lèi)中,這個(gè)工廠類(lèi)有其本身特征,也許制造過(guò)程是統(tǒng)一的,比如:制造工藝比較簡(jiǎn)單,所以名稱(chēng)叫SimpleFactory。在實(shí)際應(yīng)用中,工廠方法用得比較多一些,而且是和動(dòng)態(tài)類(lèi)裝入器組合在一起應(yīng)用,舉例

      我們以Jive的ForumFactory為例,這個(gè)例子在前面的Singleton模式中我們討論過(guò),現(xiàn)在再討論其工廠模式: public abstract class ForumFactory {

      private static Object initLock = new Object();

      private static String className = “com.jivesoftware.forum.database.DbForumFactory”;

      private static ForumFactory factory = null;

      public static ForumFactory getInstance(Authorization authorization){

      //If no valid authorization passed in, return null.if(authorization == null){

      return null;

      }

      //以下使用了Singleton 單態(tài)模式

      if(factory == null){

      synchronized(initLock){

      if(factory == null){

      ......}

      }

      } try {

      //動(dòng)態(tài)轉(zhuǎn)載類(lèi)

      Class c = Class.forName(className);

      factory =(ForumFactory)c.newInstance();} catch(Exception e){

      return null;}

      //Now, 返回 proxy.用來(lái)限制授權(quán)對(duì)forum的訪問(wèn)

      return new ForumFactoryProxy(authorization, factory,factory.getPermissions(authorization));

      }

      //真正創(chuàng)建forum的方法由繼承forumfactory的子類(lèi)去完成.public abstract Forum createForum(String name, String description)

      throws UnauthorizedException, ForumAlreadyExistsException;

      ....}

      因?yàn)楝F(xiàn)在的Jive是通過(guò)數(shù)據(jù)庫(kù)系統(tǒng)存放論壇帖子等內(nèi)容數(shù)據(jù),如果希望更改為通過(guò)文件系統(tǒng)實(shí)現(xiàn),這個(gè)工廠方法ForumFactory就提供了提供動(dòng)態(tài)接口: private static String className = “com.jivesoftware.forum.database.DbForumFactory”;你可以使用自己開(kāi)發(fā)的創(chuàng)建forum的方法代替com.jivesoftware.forum.database.DbForumFactory就可以.在上面的一段代碼中一共用了三種模式,除了工廠模式外,還有Singleton單態(tài)模式,以及proxy模式,proxy模式主要用來(lái)授權(quán)用戶對(duì)forum的訪問(wèn),因?yàn)樵L問(wèn)forum有兩種人:一個(gè)是注冊(cè)用戶 一個(gè)是游客guest,那么那么相應(yīng)的權(quán)限就不一樣,而且這個(gè)權(quán)限是貫穿整個(gè)系統(tǒng)的,因此建立一個(gè)proxy,類(lèi)似網(wǎng)關(guān)的概念,可以很好的達(dá)到這個(gè)效果.看看Java寵物店中的CatalogDAOFactory: public class CatalogDAOFactory {

      /**

      * 本方法制定一個(gè)特別的子類(lèi)來(lái)實(shí)現(xiàn)DAO模式。

      * 具體子類(lèi)定義是在J2EE的部署描述器中。

      */

      public static CatalogDAO getDAO()throws CatalogDAOSysException {

      CatalogDAO catDao = null;

      try {

      InitialContext ic = new InitialContext();//動(dòng)態(tài)裝入CATALOG_DAO_CLASS //可以定義自己的CATALOG_DAO_CLASS,從而在無(wú)需變更太多代碼 //的前提下,完成系統(tǒng)的巨大變更。

      String className =(String)ic.lookup(JNDINames.CATALOG_DAO_CLASS);

      catDao =(CatalogDAO)Class.forName(className).newInstance();

      } catch(NamingException ne){

      throw new CatalogDAOSysException(“

      CatalogDAOFactory.getDAO: NamingException while

      getting DAO type : n” + ne.getMessage());

      } catch(Exception se){

      throw new CatalogDAOSysException(“

      CatalogDAOFactory.getDAO: Exception while getting

      DAO type : n” + se.getMessage());

      }

      return catDao;

      } } CatalogDAOFactory是典型的工廠方法,catDao是通過(guò)動(dòng)態(tài)類(lèi)裝入器className獲得CatalogDAOFactory具體實(shí)現(xiàn)子類(lèi),這個(gè)實(shí)現(xiàn)子類(lèi)在Java寵物店是用來(lái)操作catalog數(shù)據(jù)庫(kù),用戶可以根據(jù)數(shù)據(jù)庫(kù)的類(lèi)型不同,定制自己的具體實(shí)現(xiàn)子類(lèi),將自己的子類(lèi)名給與CATALOG_DAO_CLASS變量就可以。

      由此可見(jiàn),工廠方法確實(shí)為系統(tǒng)結(jié)構(gòu)提供了非常靈活強(qiáng)大的動(dòng)態(tài)擴(kuò)展機(jī)制,只要我們更換一下具體的工廠方法,系統(tǒng)其他地方無(wú)需一點(diǎn)變換,就有可能將系統(tǒng)功能進(jìn)行改頭換面的變化。

      設(shè)計(jì)模式之Prototype(原型)

      定義: 用原型實(shí)例指定創(chuàng)建對(duì)象的種類(lèi),并且通過(guò)拷貝這些原型創(chuàng)建新的對(duì)象.Prototype模式允許一個(gè)對(duì)象再創(chuàng)建另外一個(gè)可定制的對(duì)象,根本無(wú)需知道任何如何創(chuàng)建的細(xì)節(jié),工作原理是:通過(guò)將一個(gè)原型對(duì)象傳給那個(gè)要發(fā)動(dòng)創(chuàng)建的對(duì)象,這個(gè)要發(fā)動(dòng)創(chuàng)建的對(duì)象通過(guò)請(qǐng)求原型對(duì)象拷貝它們自己來(lái)實(shí)施創(chuàng)建。如何使用? 因?yàn)镴ava中的提供clone()方法來(lái)實(shí)現(xiàn)對(duì)象的克隆(具體了解clone()按這里),所以Prototype模式實(shí)現(xiàn)一下子變得很簡(jiǎn)單.以勺子為例:

      public abstract class AbstractSpoon implements Cloneable {

      String spoonName;

      public void setSpoonName(String spoonName){this.spoonName = spoonName;}

      public String getSpoonName(){return this.spoonName;}

      public Object clone()

      {

      Object object = null;

      try {

      object = super.clone();

      } catch(CloneNotSupportedException exception){

      System.err.println(“AbstractSpoon is not Cloneable”);

      }

      return object;

      } } 有兩個(gè)具體實(shí)現(xiàn)(ConcretePrototype): public class SoupSpoon extends AbstractSpoon {

      public SoupSpoon()

      {

      setSpoonName(“Soup Spoon”);

      } } public class SaladSpoon extends AbstractSpoon {

      public SaladSpoon()

      {

      setSpoonName(“Salad Spoon”);

      } } 調(diào)用Prototype模式很簡(jiǎn)單: AbstractSpoon spoon = new SoupSpoon();AbstractSpoon spoon = new SaladSpoon();當(dāng)然也可以結(jié)合工廠模式來(lái)創(chuàng)建AbstractSpoon實(shí)例。

      在Java中Prototype模式變成clone()方法的使用,由于Java的純潔的面向?qū)ο筇匦?,使得在Java中使用設(shè)計(jì)模式變得很自然,兩者已經(jīng)幾乎是渾然一體了。這反映在很多模式上,如Interator遍歷模式。

      設(shè)計(jì)模式之Singleton(單態(tài))

      定義: Singleton模式主要作用是保證在Java應(yīng)用程序中,一個(gè)類(lèi)Class只有一個(gè)實(shí)例存在。在很多操作中,比如建立目錄 數(shù)據(jù)庫(kù)連接都需要這樣的單線程操作。

      還有, singleton能夠被狀態(tài)化;這樣,多個(gè)單態(tài)類(lèi)在一起就可以作為一個(gè)狀態(tài)倉(cāng)庫(kù)一樣向外提供服務(wù),比如,你要論壇中的帖子計(jì)數(shù)器,每次瀏覽一次需要計(jì)數(shù),單態(tài)類(lèi)能否保持住這個(gè)計(jì)數(shù),并且能synchronize的安全自動(dòng)加1,如果你要把這個(gè)數(shù)字永久保存到數(shù)據(jù)庫(kù),你可以在不修改單態(tài)接口的情況下方便的做到。

      另外方面,Singleton也能夠被無(wú)狀態(tài)化。提供工具性質(zhì)的功能,Singleton模式就為我們提供了這樣實(shí)現(xiàn)的可能。使用Singleton的好處還在于可以節(jié)省內(nèi)存,因?yàn)樗拗屏藢?shí)例的個(gè)數(shù),有利于Java垃圾回收(garbage collection)。

      我們常常看到工廠模式中類(lèi)裝入器(class loader)中也用Singleton模式實(shí)現(xiàn)的,因?yàn)楸谎b入的類(lèi)實(shí)際也屬于資源。如何使用?

      一般Singleton模式通常有幾種形式: public class Singleton {

      private Singleton(){}

      //在自己內(nèi)部定義自己一個(gè)實(shí)例,是不是很奇怪?

      //注意這是private 只供內(nèi)部調(diào)用

      private static Singleton instance = new Singleton();

      }

      第二種形式: public class Singleton {

      private static Singleton instance = null;public static synchronized Singleton getInstance(){

      //這個(gè)方法比上面有所改進(jìn),不用每次都進(jìn)行生成對(duì)象,只是第一次

      //使用時(shí)生成實(shí)例,提高了效率!if(instance==null)

      instance=new Singleton();return instance;} //這里提供了一個(gè)供外部訪問(wèn)本class的靜態(tài)方法,可以直接訪問(wèn)

      public static Singleton getInstance(){

      return instance;

      } }

      使用Singleton.getInstance()可以訪問(wèn)單態(tài)類(lèi)。

      上面第二中形式是lazy initialization,也就是說(shuō)第一次調(diào)用時(shí)初始Singleton,以后就不用再生成了。

      注意到lazy initialization形式中的synchronized,這個(gè)synchronized很重要,如果沒(méi)有synchronized,那么使用getInstance()是有可能得到多個(gè)Singleton實(shí)例。關(guān)于lazy initialization的Singleton有很多涉及double-checked locking(DCL)的討論,有興趣者進(jìn)一步研究。

      一般認(rèn)為第一種形式要更加安全些。使用Singleton注意事項(xiàng):

      有時(shí)在某些情況下,使用Singleton并不能達(dá)到Singleton的目的,如有多個(gè)Singleton對(duì)象同時(shí)被不同的類(lèi)裝入器裝載;在EJB這樣的分布式系統(tǒng)中使用也要注意這種情況,因?yàn)镋JB是跨服務(wù)器,跨JVM的。

      我們以SUN公司的寵物店源碼(Pet Store 1.3.1)的ServiceLocator為例稍微分析一下:

      在Pet Store中ServiceLocator有兩種,一個(gè)是EJB目錄下;一個(gè)是WEB目錄下,我們檢查這兩個(gè)ServiceLocator會(huì)發(fā)現(xiàn)內(nèi)容差不多,都是提供EJB的查詢(xún)定位服務(wù),可是為什么要分開(kāi)呢?仔細(xì)研究對(duì)這兩種ServiceLocator才發(fā)現(xiàn)區(qū)別:在WEB中的ServiceLocator的采取Singleton模式,ServiceLocator屬于資源定位,理所當(dāng)然應(yīng)該使用Singleton模式。但是在EJB中,Singleton模式已經(jīng)失去作用,所以ServiceLocator才分成兩種,一種面向WEB服務(wù)的,一種是面向EJB服務(wù)的。

      Singleton模式看起來(lái)簡(jiǎn)單,使用方法也很方便,但是真正用好,是非常不容易,需要對(duì)Java的類(lèi) 線程 內(nèi)存等概念有相當(dāng)?shù)牧私?。進(jìn)一步深入可參考:

      Double-checked locking and the Singleton pattern When is a singleton not a singleton?

      第五篇:審計(jì)模式的比較

      審計(jì)模式的比較 審計(jì)模式是審計(jì)導(dǎo)向性的目的、范圍和方法等要素的組合,它規(guī)定了審計(jì)應(yīng)從何處著手、如何著手以及何時(shí)著手等方面。按照歷史發(fā)展的順序,審計(jì)模式經(jīng)歷了賬項(xiàng)基礎(chǔ)審計(jì)模式、制度基礎(chǔ)審計(jì)模式、風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)模式三個(gè)階段。由于各階段的導(dǎo)向性目標(biāo)不同,所采用的審計(jì)程序和方法也有所不同,但是三個(gè)階段相互之間并非孤立,而是存在承前啟后的關(guān)系。

      一、賬項(xiàng)基礎(chǔ)審計(jì)模式

      特點(diǎn):(1)以會(huì)計(jì)事項(xiàng)為主線,在審查會(huì)計(jì)事項(xiàng)的基礎(chǔ)上開(kāi)展審計(jì)工作,工作量較大,適應(yīng)早期審計(jì)的需要。

      (2)主要目標(biāo)是查錯(cuò)糾弊,但不審查內(nèi)部牽制制度,不對(duì)內(nèi)部牽制制度發(fā)表評(píng)價(jià)意見(jiàn)。

      (3)主要采用查賬的方法。它要審查被審計(jì)單位在審計(jì)期間內(nèi)關(guān)于會(huì)計(jì)事項(xiàng)的會(huì)計(jì)記錄及其有關(guān)憑證,驗(yàn)算其會(huì)計(jì)金額,核對(duì)轉(zhuǎn)賬事項(xiàng),以證實(shí)賬簿和報(bào)表數(shù)字的正確性。

      (4)沒(méi)有區(qū)分階段、步驟,沒(méi)有固定的審計(jì)程序,也不重視著手審計(jì)前的準(zhǔn)備工作,只要求了解被審計(jì)單位的概況和搜集試算表、總賬、明細(xì)賬等會(huì)計(jì)資料,然后直接審查會(huì)計(jì)事項(xiàng)。

      (5)此階段形成了豐富的審計(jì)方法和技術(shù),并沿用至今,主要包括:①書(shū)面資料審計(jì)方法②財(cái)產(chǎn)物資審計(jì)方法③分析性復(fù)核方法。

      二、制度基礎(chǔ)審計(jì)模式

      特點(diǎn):(1)主要目標(biāo)是確定會(huì)計(jì)報(bào)表的公允性,盡管也揭露錯(cuò)誤和舞弊,但只是因?yàn)殄e(cuò)誤和舞弊會(huì)影響財(cái)務(wù)報(bào)表的公允性。

      (2)在評(píng)價(jià)內(nèi)部控制的基礎(chǔ)上確定審計(jì)的重點(diǎn)和范圍,并非傳統(tǒng)的詳細(xì)審計(jì),可以在保證審計(jì)結(jié)論具有一定可靠水平的前提下提高審計(jì)工作效率。

      (3)形成了標(biāo)準(zhǔn)化的審計(jì)程序,一般包括計(jì)劃、實(shí)施、完成三個(gè)階段,重視審計(jì)計(jì)劃階段,并把內(nèi)部控制的評(píng)審作為關(guān)鍵步驟,審計(jì)范圍和重點(diǎn)都比較明確。

      (4)除采用賬項(xiàng)基礎(chǔ)審計(jì)的技術(shù)方法之外,還引入了對(duì)內(nèi)部控制的符合性測(cè)試和審計(jì)抽樣。

      三、風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)模式

      風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)模式經(jīng)歷了從傳統(tǒng)風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)向現(xiàn)代風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)的轉(zhuǎn)變。

      現(xiàn)代風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)模式與傳統(tǒng)風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)模式的主要區(qū)別:

      (1)從審計(jì)風(fēng)險(xiǎn)模型來(lái)看,傳統(tǒng)風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)的風(fēng)險(xiǎn)模型為

      審計(jì)風(fēng)險(xiǎn)=固有風(fēng)險(xiǎn)*控制風(fēng)險(xiǎn)*檢查風(fēng)險(xiǎn)

      而現(xiàn)代風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)的風(fēng)險(xiǎn)模型為

      審計(jì)風(fēng)險(xiǎn)=重大錯(cuò)報(bào)風(fēng)險(xiǎn)*檢查風(fēng)險(xiǎn)

      (2)從審計(jì)思路來(lái)看,傳統(tǒng)風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)模式一般采用自下而上的審計(jì)方式,以企業(yè)的內(nèi)部控制為審計(jì)起點(diǎn),以?xún)?nèi)部控制風(fēng)險(xiǎn)評(píng)估為風(fēng)險(xiǎn)評(píng)估的重心;而現(xiàn)代風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)模式主要從企業(yè)內(nèi)外部環(huán)境、經(jīng)營(yíng)風(fēng)險(xiǎn)分析入手,以此來(lái)發(fā)現(xiàn)可能出現(xiàn)重大錯(cuò)報(bào)的領(lǐng)域及評(píng)估被審計(jì)單位的會(huì)計(jì)政策和會(huì)計(jì)估計(jì)的適當(dāng)性,加強(qiáng)了對(duì)固有風(fēng)險(xiǎn)的評(píng)估,同時(shí)仍未完全放棄自下而上的審計(jì)方式。

      (3)從審計(jì)程序來(lái)看,傳統(tǒng)風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)模式在實(shí)務(wù)中存在重程序、輕風(fēng)險(xiǎn)的傾向,而

      現(xiàn)代風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)模式則針對(duì)不同的客戶、不同的風(fēng)險(xiǎn)領(lǐng)域采取不同的審計(jì)程序,對(duì)分析性程序也更為重視。

      現(xiàn)代風(fēng)險(xiǎn)導(dǎo)向?qū)徲?jì)模式更能適應(yīng)現(xiàn)代審計(jì)環(huán)境的變化,它要求注冊(cè)會(huì)計(jì)師一重大錯(cuò)報(bào)風(fēng)險(xiǎn)的識(shí)別、評(píng)估和應(yīng)對(duì)為審計(jì)工作的主線,以提高審計(jì)效率和效果。

      下載設(shè)計(jì)模式-創(chuàng)建型模式的優(yōu)缺點(diǎn)比較word格式文檔
      下載設(shè)計(jì)模式-創(chuàng)建型模式的優(yōu)缺點(diǎn)比較.doc
      將本文檔下載到自己電腦,方便修改和收藏,請(qǐng)勿使用迅雷等下載。
      點(diǎn)此處下載文檔

      文檔為doc格式


      聲明:本文內(nèi)容由互聯(lián)網(wǎng)用戶自發(fā)貢獻(xiàn)自行上傳,本網(wǎng)站不擁有所有權(quán),未作人工編輯處理,也不承擔(dān)相關(guān)法律責(zé)任。如果您發(fā)現(xiàn)有涉嫌版權(quán)的內(nèi)容,歡迎發(fā)送郵件至:645879355@qq.com 進(jìn)行舉報(bào),并提供相關(guān)證據(jù),工作人員會(huì)在5個(gè)工作日內(nèi)聯(lián)系你,一經(jīng)查實(shí),本站將立刻刪除涉嫌侵權(quán)內(nèi)容。

      相關(guān)范文推薦

        世界各國(guó)消費(fèi)模式比較

        世界各國(guó)消費(fèi)模式比較消費(fèi)模式不僅對(duì)一個(gè)國(guó)家的經(jīng)濟(jì)增長(zhǎng)有重要推動(dòng)作用,同時(shí)也對(duì)社會(huì)經(jīng)濟(jì)可持續(xù)發(fā)展具有深遠(yuǎn)影響。本文通過(guò)比較一些典型國(guó)家消費(fèi)模式的特征,探求適合我國(guó)國(guó)情......

        不同RAID模式的優(yōu)缺點(diǎn)

        不同RAID模式的優(yōu)缺點(diǎn)近來(lái)想建立一個(gè)私有云系統(tǒng),涉及到安裝使用一臺(tái)網(wǎng)絡(luò)存儲(chǔ)服務(wù)器。對(duì)于服務(wù)器中硬盤(pán)的連接,選用哪種RAID模式能準(zhǔn)確滿足需求收集了資料,簡(jiǎn)單整理后記錄如下:......

        電子現(xiàn)金支付模式的優(yōu)缺點(diǎn)

        電子現(xiàn)金支付模式的優(yōu)缺點(diǎn) 電子現(xiàn)金支付模式有以下優(yōu)點(diǎn): (1) 使用上與傳統(tǒng)現(xiàn)金相似,比較方便和易于被接受; (2) 支付過(guò)程不必每次都經(jīng)過(guò)銀行網(wǎng)絡(luò)(即離線支付),成本低適合小額支付;......

        故障模式影響分析優(yōu)缺點(diǎn)分析

        三 故障模式影響分析優(yōu)缺點(diǎn)分析 故障模式與影響分析( fault modes and effects analysis簡(jiǎn)稱(chēng) FMEA )是指:研究產(chǎn)品的每個(gè)組成部分可能存在的故障模式并確定各個(gè)故障模式對(duì)產(chǎn)品......

        EPC模式優(yōu)缺點(diǎn)(大全5篇)

        EPC總承包模式的優(yōu)、缺點(diǎn) 優(yōu)點(diǎn) EPC總承包模式的優(yōu)點(diǎn)主要有: 1) EPC總承包商負(fù)責(zé)整個(gè)項(xiàng)目的實(shí)施過(guò)程,不再以單獨(dú)的分包商身份建設(shè)項(xiàng)目,有利于整個(gè)項(xiàng)目的統(tǒng)籌規(guī)劃和協(xié)同運(yùn)作,可以......

        機(jī)能充分發(fā)揮型模式

        “機(jī)能充分發(fā)揮型”模式美國(guó)人本主義心理學(xué)家羅杰斯認(rèn)為具有健康人格的人所表現(xiàn)的是真實(shí)的自我,他們認(rèn)為幸福并不在于全都滿足,而在于積極參與和持續(xù)的奮斗。“機(jī)能充分發(fā)揮型......

        數(shù)學(xué)教學(xué)設(shè)計(jì)三種課型模式

        課型:新授課 一年級(jí)課題:《加法》教學(xué)目標(biāo): 1、通過(guò)操作、演示,使學(xué)生知道加法的含義;能正確讀出加法算式;使學(xué)生初步體會(huì)生活中有許多問(wèn)題要用加法來(lái)解決。 2、通過(guò)學(xué)生操作、表......

        代建制與BT 模式比較

        代建制與BT 模式比較 一、 相同點(diǎn) 1、 都屬于政府投資項(xiàng)目; 2、 都要通過(guò)招投標(biāo)法定程序; 3、 都要對(duì)項(xiàng)目實(shí)施組織、管理與協(xié)調(diào)。 二、 不同點(diǎn) 1、 適用范圍不同 代建制適用于......