NotionCommotion Posted June 20, 2018 Share Posted June 20, 2018 I've definitely personally experienced improper use of inheritance which resulted in a complicated and inflexible mess. I am not saying that inheritance is evil or shouldn't be used, but just when misused, yeah, maybe "evil" is the right word. So, I've looked for opportunities to change the behavior of some of my classes by injecting different objects, and have found a few which has greatly simplified matters. But I still struggling to identify more opportunities. Most of the examples I read seem to be all the same and describe injecting an area calculator in a shape or a database interface in a mapper or some other simple example. While this is great, often it is not some defined "thing" I need to inject but a collection of behaviors which I can't seem to define a name for. For instance, we might have Admin extends User extends Person which seems good on the surface, but then I have a need for an Admin who isn't a user and things get wonkie. So, instead I could inject a Person in an Admin, but I've been told that injecting some subset class into a class (i.e. inject a barchart into a chart) isn't right either. So, where am I going with this? I guess I need just more real examples how it is done right. Any recommendations where I might find some (ideally in PHP)? Also, how would you handle the Admin/Person example without using Inheritance? Thanks Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.