Design Pattern Examples
Overview of object-oriented design patterns
facade_exercise.py
Go to the documentation of this file.
6
7from io import StringIO
8
9from .facade_interface import IDeviceNetworkHighLevel
10from .facade_highlevelsystem import CreateHighLevelInstance
11
12
13
20def _Facade_ShowIdCodes(chainIndex : int, idcodes : list) -> None:
21 output = StringIO()
22 output.write(" On chain {0}, idcodes = [ ".format(chainIndex))
23 for idcode in idcodes:
24 output.write("0x{0:X} ".format(idcode))
25 output.write("]")
26 print(output.getvalue())
27
28
29
30
44
45# ! [Using Facade in Python]
47 print()
48 print("Facade Exercise")
49
50 deviceChainFacade = CreateHighLevelInstance()
51 numChains = deviceChainFacade.GetNumChains()
52 print(" Showing idcodes of devices after a device reset (expect one device on each chain)...")
53 for chainIndex in range(0, numChains):
54 deviceChainFacade.DisableDevicesInDeviceChain(chainIndex)
55 idcodes = deviceChainFacade.GetIdcodes(chainIndex)
56 _Facade_ShowIdCodes(chainIndex, idcodes)
57
58 print(" Showing idcodes of devices after selecting all devices...")
59 for chainIndex in range(0, numChains):
60 deviceChainFacade.EnableDevicesInDeviceChain(chainIndex, 0xffffffff)
61 idcodes = deviceChainFacade.GetIdcodes(chainIndex)
62 _Facade_ShowIdCodes(chainIndex, idcodes)
63
64 print(" Done.")
65# ! [Using Facade in Python]
None _Facade_ShowIdCodes(int chainIndex, list idcodes)
Helper method to present a formatted list of idcodes for a particular device chain.
def Facade_Exercise()
Example of using the Facade Pattern.