Factory Pattern in Rust | Rust Language

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 พ.ย. 2024

ความคิดเห็น • 9

  •  2 หลายเดือนก่อน +1

    Shouldn’t the factory return an instance of the Pets object instead of the trait? Seems to be a rather limited approach like this.

    • @learning_rust
      @learning_rust  2 หลายเดือนก่อน

      Ok, so return... -> impl instead?
      'static dispatch'
      still learning - so all advice welcomed

    • @learning_rust
      @learning_rust  2 หลายเดือนก่อน +1

      Something like this?
      play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5cb6d0dc5698d7ed189ea366d6fd4b1d

    •  2 หลายเดือนก่อน +1

      @@learning_rust Yeah, my understanding of the factory pattern is that you shouldn't worry about the exact implementation. That's where the factory comes in. But I usually use design patterns fairly loosely (when I use 'em) See my other remark on what I did with it. Your stuff is really inspiring to play with the concepts

    •  2 หลายเดือนก่อน

      @@learning_rust Yes, that was my interpretation too

    • @learning_rust
      @learning_rust  2 หลายเดือนก่อน

      Understood
      I'm trying to nail the theory, and then deviate/use more loosely exactly like you say, I'm going to revist "Rust in a Month of Lunches" page 244 (I'm not on any commission, but it's such a good book).
      Thanks for taking the time to comment 👍