4 ms·
> how do you know which members of the struct really need to be populated Interfaces + duck typing? Your function shouldn’t ask for the struct, but rather for
by christophilus 5y ago
> how do you know which members of the struct really need to be populated
Interfaces + duck typing? Your function shouldn’t ask for the struct, but rather for an interface describing what it needs.
Practically, though, I often just ask for the struct because I’m a slob.
- skybrian 5y agoAn interface with many methods can have the same problem. If the function doesn't actually use every method in the interface, do you really need to implement them all? So then it might be better for the function to declare its own interface with just the methods it uses? But then, all the callers need to be changed if you decide to call another method. There's no principled solution to predicting what dependencies code might need someday. It's a matter of taste.
- crazy5sheep 5y agoAn interface with many methods is already a bad design. limiting it to a handful methods is way easier to maintain. it's fine to return an object has implement many interfaces, but you really don't need to use them all on the input side.