|
to:barstear
========== ========= ======== ========
| CDevice1 | | CDevice2| |CDevice3| ... |CDeviceN|
========== ========= ======== ========
↑ ↑ ↑ ↑
↓ ↓ ↓ ↓
Dev1Ctrler Dev2Ctrler ... ...
↑ ↑ ↑ ↑
↓ ↓ ↓ ↓
================================================= =====
| CWhat? |
================================================= ====
The picture you drew is what I think, I just borrowed from the organizational structure in the hardware system. In a hardware system, the CPU (equivalent to CWhat here) does not directly operate the peripherals, but through This is done by the hardware controller connected to the peripheral. For example, the CPU does not directly control the rotation of the hard disk (equivalent to a Device here) motor, and does not control the movement of the magnetic head. These are done with a hard disk controller (equivalent to DevXCtrler in the figure). ) Is done, what the CPU does is just write the correct control word or read the status word from the port (equivalent to the interface here) "exposed" by the controller of a different device, so to this extent, " The concept of "port" further reduces the coupling of CPU and hardware controller.
So you say that CWhat and DevXCtrler are tightly coupled, which is correct, because it is like the CPU in order to control the floppy disk, it must have a dedicated floppy disk instruction set, in order to control the hard disk, there must be a dedicated hard disk instruction set, but in fact the CPU does not have these. Instruction set is impossible. So in order to reduce the coupling of CWhat and DevXCtrler, the concept of ports can be simulated again, such as IPort.
This does cause code expansion, but the design pattern seems to be like this.If a certain code expansion can achieve high cohesion, low coupling, easy maintenance and expansion of each unit module, then this expansion is worth it.
This is just my humble opinion |
|