日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

设计模式复习-抽象工厂模式

發布時間:2025/6/17 asp.net 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 设计模式复习-抽象工厂模式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

設計模式復習-抽象工廠模式

? ? ? ? 有兩種硬件,PC和Phone,有兩種系統,Windows和Linux,現在假設PC和Phone上全都能安裝這兩個系統,并且將來硬件不會在變化,但是系統可能需要擴展,比如擴展一個Android系統,處理這樣的問題,盡量滿足OCP。

?

//FactoryMode.h

#pragma?once#include<iostream>using?namespace?std;class?CinterfaceOS?{public:virtual?void?StartOs()?=?0;virtual?void?CloseOs()?=?0;};class?CWindows?:?public?CinterfaceOS?{public:void?StartOs()?{cout?<<?"Start?Windows?OS"?<<?endl;}void?CloseOs()?{cout?<<?"Close?Windows?OS"?<<?endl;}};class?CLinux?:?public?CinterfaceOS?{public:void?StartOs()?{cout?<<?"Start?Linux?OS"?<<?endl;}void?CloseOs()?{cout?<<?"Close?Linux?OS"?<<?endl;}};class?CWindowsPC?:?public?CWindows?{public:void?StartOs()?{cout?<<?"StartWindowsPC:";CWindows::StartOs();}void?CloseOs()?{cout?<<?"CloseWindowsPC:";CWindows::CloseOs();}};class?CWindowsPhone?:?public?CWindows?{public:void?StartOs()?{cout?<<?"StartWindowsPhone:";CWindows::StartOs();}void?CloseOs()?{cout?<<?"CloseWindowsPhone:";CWindows::CloseOs();}};class?CLinuxPC?:?public?CLinux?{public:void?StartOs()?{cout?<<?"StartLinuxPC:";CLinux::StartOs();}void?CloseOs()?{cout?<<?"CloseLinuxPC:";CLinux::CloseOs();}};class?CLinuxPhone?:?public?CLinux?{public:void?StartOs()?{cout?<<?"StartLinuxPhone:";CLinux::StartOs();}void?CloseOs()?{cout?<<?"CloseLinuxPhone:";CLinux::CloseOs();}};class?CInterfaceFactory?{public:virtual?CinterfaceOS?*?CreatePcOs()?=?0;virtual?CinterfaceOS?*?CreatePhoneOs()?=?0;};class?CCreateFactoryWindows?:?public?CInterfaceFactory?{CinterfaceOS?*?CreatePcOs()?{return?new?CWindowsPC();}CinterfaceOS?*?CreatePhoneOs()?{return?new?CWindowsPhone();}};class?CCreateFactoryLinux?:?public?CInterfaceFactory?{CinterfaceOS?*?CreatePcOs()?{return?new?CLinuxPC();}CinterfaceOS?*?CreatePhoneOs()?{return?new?CLinuxPhone();}};#include?"stdafx.h"#include?"FactoryMode.h"#include?<iostream>using?namespace?std;int?main()?{CInterfaceFactory?*pHashFactoryWindows?=?NULL;CinterfaceOS?*pHashOsWindowsPC?=?NULL;CinterfaceOS?*pHashOsWindowsPhone?=?NULL;CInterfaceFactory?*pHashFactoryLinux?=?NULL;CinterfaceOS?*pHashOsLinuxPC?=?NULL;CinterfaceOS?*pHashOsLinuxPhone?=?NULL;pHashFactoryWindows?=?new?CCreateFactoryWindows();pHashOsWindowsPC?=?pHashFactoryWindows->CreatePcOs();pHashOsWindowsPhone?=?pHashFactoryWindows->CreatePhoneOs();pHashFactoryLinux?=?new?CCreateFactoryLinux();pHashOsLinuxPC?=?pHashFactoryLinux->CreatePcOs();pHashOsLinuxPhone?=?pHashFactoryLinux->CreatePhoneOs();pHashOsWindowsPC->StartOs();pHashOsWindowsPC->CloseOs();pHashOsWindowsPhone->StartOs();pHashOsWindowsPhone->CloseOs();pHashOsLinuxPC->StartOs();pHashOsLinuxPC->CloseOs();pHashOsLinuxPhone->StartOs();pHashOsLinuxPhone->CloseOs();delete?pHashOsWindowsPC;delete?pHashOsWindowsPhone;delete?pHashFactoryWindows;delete?pHashOsLinuxPC;delete?pHashOsLinuxPhone;delete?pHashFactoryLinux;//getchar();return?0;}

?

總結

以上是生活随笔為你收集整理的设计模式复习-抽象工厂模式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。