|
|
|
|
|
by reedjosh
1516 days ago
|
|
Yeah, and I kind of did that. But I've found it annoying and not great. For example in the base struct I had an interface and a ton of methods that use it. Then when I declared the concrete struct, I have to manually point the concrete type that matches that interface to the base class's interface. Composition doesn't really allow the same thing as inheritance. Composition typically means you'll have a motor and wheel struct in your car struct and maybe your car struct uses both in some drive method. Inheritance is more like having a car struct with a rev engine method, but no concrete engine set. So you can later make a Kia, set the motor to a type, and then call the base struct's rev engine method. Again, it's not impossible, just really ugly. |
|