Compound device and Composite device

Compound device就是几个设备通过一个USB Hub形成的单一设备;Composite devcie是具有多个接口的设备,每个接口代表一个独立的设备。显然,如果是想实现同样功能的话,Composite设备的方法要简单很多。


Composite USB devices expose multiple functions to a host by using multiple interfaces.

compound device is an external hub that is combined with other devices. Compound devices appear to the host as a hub with one or more non-removable devices that are connected to the hub’s ports.

对于compound device,它内置的hub和其它设备都会有各自的device address, 而compoiste device只有一个device address。实际上,从host的角度来看,compound device与一个hub上挂多个设备是等效的。


USB HID设备可以包含多种功能的报告描述符合集,这样可以实现复合设备,如带鼠标功能的USB键盘,这种复合键盘可以通过在报告描述里包含键盘和鼠标两种报告来实现,两个报告用报告ID来区分。

### Composite Design Pattern Implementation Example The **Composite Design Pattern** allows clients to treat individual objects and compositions of objects uniformly. It structures objects into tree-like hierarchies where each node can be treated as an instance of a common interface. Below is an example implementation in Python: ```python from abc import ABC, abstractmethod # Define the base Component class (interface) class Graphic(ABC): @abstractmethod def render(self): pass # Leaf Node: Represents primitive elements in the composition class Dot(Graphic): def render(self): print("Rendering a dot") class Circle(Graphic): def render(self): print("Rendering a circle") # Composite Node: Represents complex components that may contain other components class CompoundGraphic(Graphic): def __init__(self): self.children = [] def add(self, graphic): self.children.append(graphic) def remove(self, graphic): self.children.remove(graphic) def render(self): for child in self.children: child.render() # Client Code if __name__ == "__main__": # Create leaf nodes dot1 = Dot() circle1 = Circle() # Create composite nodes compound_graphic_1 = CompoundGraphic() compound_graphic_2 = CompoundGraphic() # Add children to composites compound_graphic_1.add(dot1) compound_graphic_1.add(circle1) compound_graphic_2.add(compound_graphic_1) # Render all graphics compound_graphic_2.render() ``` This code demonstrates how the `CompoundGraphic` acts as both a container and a participant in rendering operations while delegating actual work to its constituent parts such as dots and circles[^1]. When designing systems using this approach, it becomes easier to manage hierarchical relationships between different types of graphical entities without needing special cases for handling collections versus single items explicitly[^3]. Additionally, combining patterns like Singleton might help control access points within large applications but should generally remain separate concerns unless absolutely necessary due to their differing purposes[^2].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值