freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

軟件設(shè)計(jì)的五大原則-文庫吧資料

2024-08-28 23:47本頁面
  

【正文】 ctangleamp。 Rectangle::setHeight(h)。 }。 void Square::setWidth(double w){ Rectangle::setWidth(w)。 void setHeight(double h)。} }。} double getWidth() const{return width。 public: void setWidth(double w){width=w。 doulbe width。(s).Draw()。(s).Draw()。 void DrawShape(const Shapeamp。 double itsSide。 void Draw()const。 }。 Point itsCenter。 struct Circle:public Shape{ Circle():Shape(circle){ }。 struct shape{ enum ShapeType{square,circle} itsType。那么這個(gè)測試違反了 OCP——因?yàn)?f無法對 Base的所有派生類都是封閉的 ? 示例 1: struct Point{double x,y。d) 會導(dǎo)致錯(cuò)誤 顯然 D對于 f是脆弱的。 ? 分析: – 違法這個(gè)職責(zé)將導(dǎo)致程序的 脆弱 性和對 OCP的違反 例如:基類 Base,派生類 Derived,派生類實(shí)例 d,函數(shù) f(Base* p)。 – 事實(shí)上在 C++中我們可以在鏈接時(shí)選擇要使用的表。 ? 對于不同的 Shapes的繪制順序的變化不封閉的唯一部分就是表本身。 } return thisOrd argOrd。 (thisOrd 0)) done = true。 if ((argOrd 0) amp。 if (tableEntry != 0){ if (strcmp(tableEntry, thisType) == 0) thisOrd = i。 !done。 int argOrd = 1。 bool done = false。 s) const{ const char* thisType = typeid(*this).name()。 char* Shape::typeOrderTable[] = { typeid(Circle).name(), typeid(Square).name(), 0 }。 } private: static char* typeOrderTable[]。 bool operator(const Shapeamp。 virtual bool Precedes(const Shapeamp。 } 這個(gè)程序符合 OCP嗎?? 利用 “ 數(shù)據(jù)驅(qū)動 ” 的方法獲得封閉性 include typeinfo include string include iostream using namespace std。 s) const{ if (dynamic_castSquare*(s)) return true。 i++) (*i)Draw()。 for(i=()。 sort((), (), LesspShape*())。} } void DrawAllShapes(vectorShape*amp。} }。 bool operatorconst Shapeamp。 virtual bool Precedes(const Shapeamp。 } – 例子 2(續(xù)) ? 再看這些批判 再加入 “ 三角形 ” 將變得十分簡單: – 僵化的 增加 Triangle會導(dǎo)致 Shape、 Square、 Circle以及 DrawAllShapes的重新編譯和部署 – 脆弱的 因?yàn)榇嬖诖罅康募入y以查找又難以理解的 Switch和 If語句,修改稍有不慎,程序就會莫明其妙的出錯(cuò) – 牢固的 想在一個(gè)程序中復(fù)用 DrawAllShapes,都必須帶上 Circle、 Square,即使那個(gè)程序不需要他們 ? 謊言: – 上述代碼并不完全封閉 ——“如果我們希望正方形在所有圓之前繪制 ” 會怎么樣? ——對繪圖的順序無法實(shí)現(xiàn)封閉 ?更糟糕的是,剛才的設(shè)計(jì)反而成為了實(shí)現(xiàn) “ 正方形在所有圓之前繪制 ” 功能的障礙。i!=()。 list){ vectorShape*::iterator i。 }。 }。 }。 break。 break。i++){ struct Shape* s=list[i]。 for(i=0。 typedef struct Shape * ShapePointer。 CPoint itsTopLeft。 struct Square{ ShapeType itsType。 CPoint itscenter。 struct Circle{ ShapeType itsType。 struct Shape{ ShapeType itsType。允許 擴(kuò)展具體的實(shí)現(xiàn)形式(開放),同時(shí)將這種擴(kuò)展與策略隔離開來,使 其對上層的策略透明(封閉)。 ?而接口是策略的一個(gè)組成部分,他根 client端的關(guān)系更加密切 ?我們應(yīng)該這樣想問題: ClientInterface中定義了 client期 望 Server做什么,而 server具體類是對 client這種要求的 一種具體實(shí)現(xiàn)。 }。 class server:public ClientInterface{ int serverData。 class ClientInterface{ virtual void ServerFunc()=0。 CI):ci(CI){} void useServer(){ ()。 ci。 } }。 public: client(serveramp。 class client{ server1amp。 public: void ServerFunc()。 }。 class server{ int serverData。 SER):s(SER){} void useServer(){ ()。 s。如果我們想要讓 client調(diào)用一個(gè)新的 server類,那么我們不得不修改 client的源代碼 ?從而帶來編譯、鏈接、部署等一系列的問題。 }。 class server{ int serverData。 SER):s(SER) {} void useServer(){ ()。 s。將這兩個(gè)職責(zé)耦合在一起,將導(dǎo)致每次因?yàn)闃I(yè)務(wù)規(guī)則變化調(diào)整Employee類時(shí),所有持久化部分的代碼也要跟著變化 2. 開放封閉原則( OCP) ? 陳述: – 軟件實(shí)體(類、模塊、函數(shù)等)應(yīng)該是可以擴(kuò)展的,同時(shí)還可以是不必修改的,更確切的說,函數(shù)實(shí)體應(yīng)該: ( 1)對擴(kuò)展是開放的 當(dāng)應(yīng)用的需求變化時(shí),我們可以對模塊進(jìn)行擴(kuò)展,使其具有滿足改變的新的行為 ——即,我們可以改變模塊的功能 ( 2)對更改是封閉的 對模塊進(jìn)行擴(kuò)展時(shí),不必改動已有的源代碼或二進(jìn)制代碼。 ? 常見錯(cuò)誤提醒: – 持久化與業(yè)務(wù)規(guī)則的耦合。 ModemI
點(diǎn)擊復(fù)制文檔內(nèi)容
黨政相關(guān)相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1