Object Oriented Programming
OOP
Compréhension
()
: Objects Contain Data and Behavior
: Encapsulation that Hides Implementation Details
:typepartagé Inheritance as a Type System and as Code Sharing
trait object
Box
trait object,Rust , —— pub trait Draw { fn draw(&self); } // trait object pub struct Screen { pub components: Vec<Box<dyn Draw>>, } impl Screen { pub fn run(&self) { for component in self.components.iter() { component.draw(); } } } // generic type + trait buond pub struct Screen<T: Draw> { pub components: Vec<T>, } impl<T> Screen<T> where T: Draw, { pub fn run(&self) { for component in self.components.iter() { component.draw(); } } }