Hello all,
I am coming from an OOP background and I am trying to find how to do things the "rust" way.
I want to create a toy program managing multiple "windows".
The windows would have some attributes like the dimension, the visibiliy, and some common associated method to resize, hide, the window. However, I want them to have at least a different render() method to display different information.
So in a typical OOP way, I would have created a GenericWindow super class, and then in a derived class like Footer::GenericWindow and Header::GenericWindows reimplement different render().
I have been thinking that I could create a "Windowable" trait but since trait only contains methods and no attribute (like width and height this seems a bit awkward)
So currently, I am more inclined to create a struct Window{}, keep all the generic code in the associated implementation, and then move the specific part in other struct like
struct Window{
width: u32,
height: u32
...
}
impl Window{
fn resize(&self) --> Window{
....
}
and then having
struct Footer{
win: Window
}
impl Footer{
fn render(&self) {
...
}
struct Header{
win: Window
}
impl Header{
fn render(&self) {
...
}
Is this a good approach ? Is there a better way to separate the different concern ? Is there a more idiomatic approach ?
I am trying to rewire my brain to embrace new concepts, this is both painful and enlightening.
Thanks in advance