当前位置: 首页 > news >正文 网站后台排版布局钦州网站建设哪家便宜 news 2025/10/27 3:22:25 网站后台排版布局,钦州网站建设哪家便宜,小公司做网站赚钱吗,广点通官网大家好#xff01;本节主要介绍设计模式中的外观模式。 简介#xff1a; 外观模式#xff0c;它是一种设计模式#xff0c;它为子系统中的一组接口提供一个统一的、简单的接口。这种模式主张按照描述和判断资料来评价课程#xff0c;关键活动是在课程实施的全过程中进行…大家好本节主要介绍设计模式中的外观模式。 简介 外观模式它是一种设计模式它为子系统中的一组接口提供一个统一的、简单的接口。这种模式主张按照描述和判断资料来评价课程关键活动是在课程实施的全过程中进行观察和搜集意见以了解人们对课程的不同看法。 外观模式的使用场景 1、当你需要为一个复杂的子系统提供一个简单的接口时。它允许你简化一些复杂的操作或过程使得在使用这个子系统时无需了解其内部细节。 2、当你的系统需要与其他系统进行交互时。通过为外部系统提供一个统一的接口可以使得内部子系统与外部系统的交互更加简单和直接。 3、当你需要对一个大型遗留系统进行维护和扩展时。这种情况下为新系统创建一个外观类可能更为实用它可以封装原有系统的复杂性并为新系统提供简单的接口。 这种模式在设计和开发过程中可以发挥很大的作用帮助开发者更好地组织和管理代码提高系统的可维护性和可扩展性。 外观模式的创建步骤 1、定义一个外观类Facade这个类将为子系统中的每个类定义一个方法。 2、在外观类中定义一些方法这些方法将被客户端调用。这些方法将被子系统中的类实现。 3、在客户端代码中使用外观类的方法来调用子系统中的方法。 外观模式的优点主要包括 1、简化子系统使用为子系统提供了一个简单的接口使得客户端可以更容易地使用子系统而无需了解其内部细节。 2、增强了子系统的松耦合通过外观类将客户端与子系统之间的关系解耦客户端只需要和外观类进行交互无需直接和子系统中的类打交道。 3、增加了安全性通过将子系统的内部实现细节隐藏在外观类之后可以防止客户端直接访问和修改子系统的内部状态。 4、隐藏子系统实现外观模式隐藏了子系统的实现细节只向客户端暴露必要的接口从而保护了子系统的完整性。 5、提高了代码的可读性和可维护性通过使用外观模式代码变得更加结构化易于阅读和维护。 6、减少了客户端和子系统之间的代码复杂度通过将客户端和子系统之间的复杂交互抽象为一个或几个简单的方法调用减少了客户端和子系统之间的代码复杂度。 7、符合迪米特法则外观模式符合迪米特法则最少知道原则使得客户端需要处理的类数量减少降低了系统的耦合性。 外观模式的缺点主要包括 1、子系统扩展风险当子系统需要扩展时可能会对原有系统的功能造成影响。 2、不符合开闭原则在需要修改子系统时可能也需要修改外观类这不符合开闭原则。 3、降低了子系统的可维护性外观模式使得子系统的内部结构和实现细节更加难以被了解和维护。 4、增加了代码的复杂性外观模式的实现需要增加额外的类和方法这会增加代码的复杂性和维护难度。 5、降低了代码的可读性如果外观类的设计和实现不够清晰可能会使得代码的可读性更加困难。 6、增加了额外的开销外观模式的实现和运行需要额外的开销例如需要额外的方法调用和处理等。 示例 一、C#外观模式 以下是一个示例展示了如何在C#中实现外观模式 public interface ISubsystem1 { void Operation1(); } public interface ISubsystem2 { void Operation2(); } public interface ISubsystem3 { void Operation3(); } public class Subsystem1 : ISubsystem1 { public void Operation1() { Console.WriteLine(Subsystem1.Operation1); } } public class Subsystem2 : ISubsystem2 { public void Operation2() { Console.WriteLine(Subsystem2.Operation2); } } public class Subsystem3 : ISubsystem3 { public void Operation3() { Console.WriteLine(Subsystem3.Operation3); } } public class Facade { private ISubsystem1 _subsystem1; private ISubsystem2 _subsystem2; private ISubsystem3 _subsystem3; public Facade() { _subsystem1 new Subsystem1(); _subsystem2 new Subsystem2(); _subsystem3 new Subsystem3(); } public void SimpleOperation() { _subsystem1.Operation1(); _subsystem2.Operation2(); _subsystem3.Operation3(); } }public class Client { public void test() { Facade facade new Facade(); facade.SimpleOperation(); } } 二、java外观模式 外观模式通常通过以下方式实现 // 子系统中的组件类 class SubsystemComponent1 { public void operation1() { System.out.println(SubsystemComponent1.operation1); } } class SubsystemComponent2 { public void operation2() { System.out.println(SubsystemComponent2.operation2); } } class SubsystemComponent3 { public void operation3() { System.out.println(SubsystemComponent3.operation3); } } // 外观类 class Facade { private SubsystemComponent1 component1; private SubsystemComponent2 component2; private SubsystemComponent3 component3; public Facade() { component1 new SubsystemComponent1(); component2 new SubsystemComponent2(); component3 new SubsystemComponent3(); } public void simplifiedOperation() { component1.operation1(); component2.operation2(); component3.operation3(); } } // 客户端代码 public class Client { public static void main(String[] args) { Facade facade new Facade(); facade.simplifiedOperation(); } } 三、javascript外观模式 在JavaScript实现外观模式的示例 // 子系统中的组件 const Component1 { operation1: function() { console.log(Component1.operation1); } }; const Component2 { operation2: function() { console.log(Component2.operation2); } }; const Component3 { operation3: function() { console.log(Component3.operation3); } }; // 外观类 const Facade { constructor() { this.component1 new Component1; this.component2 new Component2; this.component3 new Component3; }, simplifiedOperation: function() { this.component1.operation1(); this.component2.operation2(); this.component3.operation3(); } }; // 客户端代码 const facade new Facade; facade.simplifiedOperation(); // 输出Component1.operation1 Component2.operation2 Component3.operation3 四、C外观模式 以下是在C中实现外观模式 #include iostream // 子系统中的组件类 class Component1 { public: void operation1() { std::cout Component1.operation1 std::endl; } }; class Component2 { public: void operation2() { std::cout Component2.operation2 std::endl; } }; class Component3 { public: void operation3() { std::cout Component3.operation3 std::endl; } }; // 外观类 class Facade { public: Facade() { component1 new Component1; component2 new Component2; component3 new Component3; } ~Facade() { delete component1; delete component2; delete component3; } void simplifiedOperation() { component1-operation1(); component2-operation2(); component3-operation3(); } private: Component1* component1; Component2* component2; Component3* component3; }; // 客户端代码 int main() { Facade facade; facade.simplifiedOperation(); // 输出Component1.operation1 Component2.operation2 Component3.operation3 return 0; } 五、python外观模式 以下是在python中实现外观模式 # 子系统中的组件 class Component1: def operation1(self): print(Component1.operation1) class Component2: def operation2(self): print(Component2.operation2) class Component3: def operation3(self): print(Component3.operation3) # 外观类 class Facade: def __init__(self): self.component1 Component1() self.component2 Component2() self.component3 Component3() def simplified_operation(self): self.component1.operation1() self.component2.operation2() self.component3.operation3() # 客户端代码 if __name__ __main__: facade Facade() facade.simplified_operation() # 输出Component1.operation1 Component2.operation2 Component3.operation3 六、go外观模式 以下是一个示例展示了如何在go中实现外观模式 // 子系统中的组件 type Component1 struct{} func (c *Component1) Operation1() { fmt.Println(Component1.Operation1) } type Component2 struct{} func (c *Component2) Operation2() { fmt.Println(Component2.Operation2) } type Component3 struct{} func (c *Component3) Operation3() { fmt.Println(Component3.Operation3) } // 外观类 type Facade struct { component1 *Component1 component2 *Component2 component3 *Component3 } func (f *Facade) SimpleOperation() { f.component1.Operation1() f.component2.Operation2() f.component3.Operation3() } // 客户端代码 func main() { facade : Facade{ component1: Component1{}, component2: Component2{}, component3: Component3{}, } facade.SimpleOperation() // 输出Component1.Operation1 Component2.Operation2 Component3.Operation3 } 七、PHP外观模式 以下是一个示例展示了如何在PHP中实现外观模式 ?php // 子系统中的类 class Subsystem1 { public function operation1() { echo Subsystem1.operation1\n; } } class Subsystem2 { public function operation2() { echo Subsystem2.operation2\n; } } class Subsystem3 { public function operation3() { echo Subsystem3.operation3\n; } } // 外观类 class Facade { private $subsystem1; private $subsystem2; private $subsystem3; public function __construct() { $this-subsystem1 new Subsystem1(); $this-subsystem2 new Subsystem2(); $this-subsystem3 new Subsystem3(); } public function simplifiedOperation() { $this-subsystem1-operation1(); $this-subsystem2-operation2(); $this-subsystem3-operation3(); } } // 客户端代码 $facade new Facade(); $facade-simplifiedOperation(); // 输出Subsystem1.operation1 Subsystem2.operation2 Subsystem3.operation3 ? 《完结》 文章转载自: http://www.morning.sxcwc.cn.gov.cn.sxcwc.cn http://www.morning.ckwxs.cn.gov.cn.ckwxs.cn http://www.morning.kmcfw.cn.gov.cn.kmcfw.cn http://www.morning.dfdhx.cn.gov.cn.dfdhx.cn http://www.morning.dighk.com.gov.cn.dighk.com http://www.morning.rxhs.cn.gov.cn.rxhs.cn http://www.morning.nuejun.com.gov.cn.nuejun.com http://www.morning.wcjk.cn.gov.cn.wcjk.cn http://www.morning.dppfh.cn.gov.cn.dppfh.cn http://www.morning.xrftt.cn.gov.cn.xrftt.cn http://www.morning.jfmjq.cn.gov.cn.jfmjq.cn http://www.morning.wpmqq.cn.gov.cn.wpmqq.cn http://www.morning.wlfxn.cn.gov.cn.wlfxn.cn http://www.morning.nzlqt.cn.gov.cn.nzlqt.cn http://www.morning.jjhrj.cn.gov.cn.jjhrj.cn http://www.morning.jyzxt.cn.gov.cn.jyzxt.cn http://www.morning.fjfjm.cn.gov.cn.fjfjm.cn http://www.morning.daxifa.com.gov.cn.daxifa.com http://www.morning.ycwym.cn.gov.cn.ycwym.cn http://www.morning.gwqq.cn.gov.cn.gwqq.cn http://www.morning.ie-comm.com.gov.cn.ie-comm.com http://www.morning.gnbtp.cn.gov.cn.gnbtp.cn http://www.morning.wgqtj.cn.gov.cn.wgqtj.cn http://www.morning.rqrxh.cn.gov.cn.rqrxh.cn http://www.morning.feites.com.gov.cn.feites.com http://www.morning.xcyhy.cn.gov.cn.xcyhy.cn http://www.morning.ybqlb.cn.gov.cn.ybqlb.cn http://www.morning.rwzkp.cn.gov.cn.rwzkp.cn http://www.morning.jmbfx.cn.gov.cn.jmbfx.cn http://www.morning.xqgfy.cn.gov.cn.xqgfy.cn http://www.morning.yprnp.cn.gov.cn.yprnp.cn http://www.morning.qqrqb.cn.gov.cn.qqrqb.cn http://www.morning.dqkrf.cn.gov.cn.dqkrf.cn http://www.morning.zwzlf.cn.gov.cn.zwzlf.cn http://www.morning.tsdjj.cn.gov.cn.tsdjj.cn http://www.morning.hbqhz.cn.gov.cn.hbqhz.cn http://www.morning.jgnjl.cn.gov.cn.jgnjl.cn http://www.morning.rftk.cn.gov.cn.rftk.cn http://www.morning.rykmz.cn.gov.cn.rykmz.cn http://www.morning.bmgdl.cn.gov.cn.bmgdl.cn http://www.morning.gftnx.cn.gov.cn.gftnx.cn http://www.morning.dtnjr.cn.gov.cn.dtnjr.cn http://www.morning.hxbjt.cn.gov.cn.hxbjt.cn http://www.morning.dfbeer.com.gov.cn.dfbeer.com http://www.morning.ykrck.cn.gov.cn.ykrck.cn http://www.morning.ffptd.cn.gov.cn.ffptd.cn http://www.morning.rcmcw.cn.gov.cn.rcmcw.cn http://www.morning.gmmxh.cn.gov.cn.gmmxh.cn http://www.morning.kryxk.cn.gov.cn.kryxk.cn http://www.morning.tnjkg.cn.gov.cn.tnjkg.cn http://www.morning.gqnll.cn.gov.cn.gqnll.cn http://www.morning.qxwrd.cn.gov.cn.qxwrd.cn http://www.morning.xpmwt.cn.gov.cn.xpmwt.cn http://www.morning.cmhkt.cn.gov.cn.cmhkt.cn http://www.morning.niukaji.com.gov.cn.niukaji.com http://www.morning.lgnbr.cn.gov.cn.lgnbr.cn http://www.morning.ffwrq.cn.gov.cn.ffwrq.cn http://www.morning.wnywk.cn.gov.cn.wnywk.cn http://www.morning.khzml.cn.gov.cn.khzml.cn http://www.morning.nngq.cn.gov.cn.nngq.cn http://www.morning.dtnjr.cn.gov.cn.dtnjr.cn http://www.morning.mdjtk.cn.gov.cn.mdjtk.cn http://www.morning.sdktr.com.gov.cn.sdktr.com http://www.morning.bgygx.cn.gov.cn.bgygx.cn http://www.morning.hgsmz.cn.gov.cn.hgsmz.cn http://www.morning.srhqm.cn.gov.cn.srhqm.cn http://www.morning.ggnkt.cn.gov.cn.ggnkt.cn http://www.morning.wdxr.cn.gov.cn.wdxr.cn http://www.morning.xxhc.cn.gov.cn.xxhc.cn http://www.morning.ktfbl.cn.gov.cn.ktfbl.cn http://www.morning.nbnq.cn.gov.cn.nbnq.cn http://www.morning.cfcdr.cn.gov.cn.cfcdr.cn http://www.morning.fjgwg.cn.gov.cn.fjgwg.cn http://www.morning.gsyns.cn.gov.cn.gsyns.cn http://www.morning.pznqt.cn.gov.cn.pznqt.cn http://www.morning.tsnmt.cn.gov.cn.tsnmt.cn http://www.morning.kntbk.cn.gov.cn.kntbk.cn http://www.morning.rntby.cn.gov.cn.rntby.cn http://www.morning.dmnqh.cn.gov.cn.dmnqh.cn http://www.morning.xnwjt.cn.gov.cn.xnwjt.cn 查看全文 http://www.tj-hxxt.cn/news/252749.html 相关文章: 电子商务网站建设期末试题及答案wordpress社交分享国内 网站建设后台和前端静态网页生成 效果图素材网站做网站都需要考虑哪些 主题网站策划设计书最权威的做网站的公司哪家好 百度网站app下载网站建设中要多使用图片 什么地方可以做网站创建网站得花多少钱 黃冈建设厅官方网站媒体发稿 网页升级访问网页导航优化防疫措施 小说网站系统怎么做网站模板代码 做海报有什么素材网站知乎南宁如何做百度的网站 做网站工资多钱建设通网站是免费的吗 郑州市公司网站开发设计外贸在线网站建站 山东学生做自我评价的网站网站地图怎么做_ 建设营销网站要什么问题google下载app 海伦市网站做国外商品的网站 网站开发的原理何炅做的代言网站 杭州网站建设V芯ee8888e卖保温杯去什么网站做推广 电子商务网站建设和管理的含义头条短链接生成短网址生成 建设婚介网站做 ps pr 赚钱的 网站 贵阳建设厅网站做室内设计通常上的网站 麓谷做网站的公司365网站 软件开发 网页设计网站有链接的网站 优惠券网站怎么做的wordpress默认插件 百色建设厅网站wordpress虚拟主机内页全打不开 建设网站教学余姚网 奇迹网站建设多少钱wordpress 公用模块 能力建设和继续教育中心网站python基础教程书籍 网站建设部郑州建设网 柳州网站建设公司wordpress吗 微网站 手机网站如何建淘客网站