An object of type A contains a B, which contains a C, which contains a D, which contains an E, which contains an F, which has a Foo() method.
I want to be able to call Foo() from the A.
One solution might be to add an E.Foo() method which calls F.Foo(), and a D.Foo() method which calls E.Foo(), and a C.Foo() method which calls D.Foo(), and a B.Foo() method which calls C.Foo(), and an A.Foo() method which calls B.Foo(). That seems repetitive, especially when we later decide we want to call F.Bar() from the A.
Another solution might be to make the B publicly accessible from the A, C publicly accessible from the B, etc; but this isn't good encapsulation.
Are there any other strategies for making the methods of deeply nested children accessible from higher levels?
I'm working in C# at the moment, but I'm hoping for something language-agnostic.
Aucun commentaire:
Enregistrer un commentaire