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