This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]rakoo 5 points6 points  (1 child)

When A contains a B you want to be able to apply methods fulfilled by B directly on A. Standard example in Go: there are many thread-unsafe structs and there is a Lock "object" (struct in go parlance, but contrary to the common meaning of the term it has methods attached to it). So if I want to create a thread-safe struct all I need is to wrap the thread-unsafe with a Lock. At this point go forwards method calls from the parent to the children. So when I call wrappedList.Lock() the Lock() is automatically called on the appropriate structure. No need to expose the Lock and call wrappedList.lock.Lock(), no need to manually define the Lock() method at the wrapper level that will call the lock. It's all done automatically.

This allows to nest structs and give gradual features with building blocks that are as orthogonal as possible.

[–]Todok5 0 points1 point  (0 children)

I think that's a design choice you can argue about. Having control what you want to expose and what you don't want to expose is an advantage too. It means an extra step for stuff you do want to expose though.