Rust语言之GoF设计模式:抽象工厂模式

抽象工厂解决了在不指定具体类的情况下创建整个产品系列的问题。 抽象工厂的抽象接口: lib.rs pub trait Button {     fn press(&self); } pub trait Checkbox {     fn switch (&self); } ///  抽象工厂是通过泛型实现的,它允许编译器创建一个不需要在运行时进行动态调度的代码。 pub trait GuiFactory {     type B: Button;     type C: Checkbox;     fn create_button(&..

相关推荐 去reddit讨论