Hi All - the documentation for the `ComponentResou...
# general
l
Hi All - the documentation for the
ComponentResource
pattern never provides an example of subclassing a
ComponentResource
to specialise a more general abstraction. Is inheritance discouraged?
l
Composition is the normal pattern. Inheritance can be used, but it's just not as common.
l
Thanks @little-cartoon-10569 - I'd assumed as much, but figured there might have been a reason why it wasn't shown in the documentation. Is the usual compositional pattern to create a new more specialised type/component resource, and then have the new type simply carry the more general type within, assigned to one of the instance attributes?
l
Yes. Since you can't inherit from the cloud resources (what kind of a bucket is a kind-of S3 bucket?), and all you can do is configure them (a self-cleaning S3 bucket is an ordinary S3 bucket, with certain lifecycle rules applied.. it's not a subclass of an S3 bucket) or compose them (an auto-backed-up bucket is an S3 bucket with another S3 bucket and a lambda that copies any changes based on certain events), then composition is generally more suited. Plus, it's easier to grok when reading the code. Inheritance necessitates a lot of boilerplate, classes in other files, and related messiness.
l
Yep, makes sense. Thanks for your input @little-cartoon-10569 🙂