When a module is imported into a Ruby class, is it similar to composition?

When you import a module into a class, is it similar in nature to the composition of OOP?

+3
source share
2 answers

No, this is more like multiple inheritance, but not completely the same thing. Modules can be used for mixed functions, so you do not need to rewrite the same code for multiple classes. Composition is where objects contain references to other objects.

+6
source

I may have mixed terminology for the design pattern, but have you looked at def_delegatorand def_delegatorsfrom the Ruby standard library forwardable?

0
source

Source: https://habr.com/ru/post/1768758/


All Articles