Design mode 11-Bridging mode

Source: Internet
Author: User

Bridging mode: Separates the abstracted part from its implementation (methods, operations) so that they can change independently. (a dependency is injected between the two by a constructor function)

1 namespaceDesignmodel. Bridging mode2 {3 4     /// <summary>5     ///Manipulating abstract Classes6     /// </summary>7     Abstract classfileoperate8     {9          Public Abstract voidOperate (stringtype);Ten     } One  A     classexport:fileoperate -     { -          Public Override voidOperate (stringtype) the         { -             Switch(type)//This can be further optimized, but does not affect the description of this mode -             { -                 default: +Console.WriteLine ("Export"+type); -                      Break; +             } A         } at     } -  -     classconvent:fileoperate -     { -          Public Override voidOperate (stringType) = Console.WriteLine ("Conversion"+type); -  in     } -  to  +  -     Abstract classFile the     { *         protectedFileoperate Fileoperate {Get;Set; } $          Public voidSetoperate (fileoperate fo) = Fileoperate =fo;Panax Notoginseng  -          Public Abstract voidOperate (); the     } +  A     classExcel:file the     { +          Public Override voidOperate () =fileoperate.operate (nameof (Excel)); -     } $  $     classText:file -     { -          Public Override voidOperate () =fileoperate.operate (nameof (Text)); the     } - Wuyi } the  -   Static voidBridging mode () Wu         { -File f =NewExcel (); AboutFileoperate fo =NewExport (); $F.setoperate (FO);//specifying an action type for a file -F.operate ();//invokes the specified action -}
View Code

The code used to give the impression of a combination of patterns, the same is the idea of divide and conquer, the difference is that: Bridge mode after the original business decomposition, parts can be freely changed, and then assembled to use. The combination mode is the same part of the decomposition, can be combined into other parts to reuse, is a tree-like structure.

Design mode 11-Bridging mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.