Re: Alternatives for encapsulation when using composition instead of inheritance
| From: | Mike Schinkel | Date: | Thu, 26 Aug 2021 20:01:33 +0000 |
| Subject: | Re: Alternatives for encapsulation when using composition instead of inheritance | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-115867@lists.php.net to get a copy of this message | ||
> On Aug 26, 2021, at 9:47 AM, Olle Härstedt <olleharstedt@gmail.com> wrote:
>
> Don't know if this already exists, but maybe we could consider
> brainstorming or gather alternatives for different types of
> encapsulation when using composition? Currently, encapsulation like
> private and protected is only possible when using inheritance - when
> using composition, that is, class A is using (aggregating) class B,
> your only alternative is public, so full visibility (or
> getters/setters, which also is full visibility, since you can't limit
> who's using those methods).
When you say "composition" I think of traits, but it does not appear that is what you
mean?
I have often wanted to be able to create a trait-private property so that I could write a
trait and be confident that the classes that use it don't start using its internal
properties and tie my hands in terms of being able to upgrade the trait to better internal
approaches as I evolve the trait.
Would trait-private address any part of what you need? Or would other trait-specific visibility
address what you need?
And if not, what about traits makes them not-applicable here? Maybe we could also address that?
-Mike