Design Pattern Examples
Overview of object-oriented design patterns
Facade_Exercise.cs
Go to the documentation of this file.
1
5
6using System;
7
9{
26 internal class Facade_Exercise
27 {
34 void _Facade_ShowIdCodes(int chainIndex, uint[] idcodes)
35 {
36 Console.Write(" On chain {0}, idcodes = [ ", chainIndex);
37 foreach (uint idcode in idcodes)
38 {
39 Console.Write("0x{0:X} ", idcode);
40 }
41 Console.WriteLine("]");
42 }
43
47 // ! [Using Facade in C#]
48 public void Run()
49 {
50 Console.WriteLine();
51 Console.WriteLine("Facade Exercise");
52
54 int numChains = deviceChainFacade.NumChains;
55 Console.WriteLine(" Showing idcodes of devices after a device reset (expect one device on each chain)...");
56 for (int chainIndex = 0; chainIndex < numChains; ++chainIndex)
57 {
58 deviceChainFacade.DisableDevicesInDeviceChain(chainIndex);
59 uint[] idcodes = deviceChainFacade.GetIdcodes(chainIndex);
60 _Facade_ShowIdCodes(chainIndex, idcodes);
61 }
62
63 Console.WriteLine(" Showing idcodes of devices after selecting all devices...");
64 for (int chainIndex = 0; chainIndex < numChains; ++chainIndex)
65 {
66 deviceChainFacade.EnableDevicesInDeviceChain(chainIndex, 0xffffffff);
67 uint[] idcodes = deviceChainFacade.GetIdcodes(chainIndex);
68 _Facade_ShowIdCodes(chainIndex, idcodes);
69 }
70 Console.WriteLine(" Done.");
71 }
72 // ! [Using Facade in C#]
73 }
74}
Class factory for the complicated sub-system class. Part of the Facade pattern example.
static IDeviceNetworkHighLevel CreateHighLevelInstance()
Class factory for a singleton instance of the sub-system class.
Example of using the Facade Pattern in C#.
void Run()
Executes the example for the Facade Pattern in C#.
void _Facade_ShowIdCodes(int chainIndex, uint[] idcodes)
Helper method to present a formatted list of idcodes for a particular device chain....
Represents a high level view of a complex network of device chains. A device chain can be thought of ...
void DisableDevicesInDeviceChain(int chainIndex)
Resets the given device chain so that all devices except the TAP controller is no longer visible.
int NumChains
The number of device chains available from the sub-system.
void EnableDevicesInDeviceChain(int chainIndex, uint selectMask)
Make visible certain devices in the given device chain. The selectMask value has a bit set for each T...
uint[] GetIdcodes(int chainIndex)
Returns a list of all idcodes from all selected devices in the given device chain.
The namespace containing all Design Pattern Examples implemented in C#.