Subclassing in Python Redux
hynek.me
hynek.me
I really wanted these instances to be indistinguishable from ordinary `dict` objects as far as interface goes, so it seemed like an optimal use-case for inheritance. But in hindsight it seems like the "composition over inheritance" principle is ushering me to stash k,v pairs in a dictionary attribute of an ordinary (non-subclassed) class object and simply define methods such as update, delete, __setitem__, etc., rather than inheriting them. I don't think that's unreasonable, but the bigger problem I see with that approach is has to do with type dispatching: what if a user of this class is checking whether an object is an instance of `dict` (or `typing.Mapping` for that matter)?
Incredible. This appears to be exactly the solution to my problem. Thanks! (And, if thunner happens to come across this: thanks, from a former TA of yours!)
https://eev.ee/blog/2013/03/03/the-controller-pattern-is-awf...
What? He lost me there. While that fellow clearly knows a lot more about OOP than me, statements like that, which are not exactly self-evident and go against prior best practices ("don't repeat thyself") need to be justified, otherwise it just looks like just some other random dude's opinion piece.