v_melnik has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I would like you to share your opinions on the matter of passing the reference to a common object between a library components.
Let's imagine that we have a complex library that consists of a bunch of classes. There is the Library::Logger class that is being used by other components (e.g. the initialization method of Library initializes an object of the Library::Logger class and then the Library-based object uses the Library::Logger-based object to call the logging methods.
There are many other sub-classes that needs to use the same object too: Library::Foo, Library::Bar, Library::Baz. Moreover, there are Library::Foo::Schmoo, Library::Bar::Schmar and Library::Baz::Schmaz sub-classes, there are dozens of classes. The question is: how to let them all have the reference to the logger that had been initialized once by the Library-based object?
I see the following ways to acheive it:
What do you think, which way seems to be better? What way would you propose? How do you solve this problem for yourself?
Many thanks in advance!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing the logger's object
by stevieb (Canon) on Nov 13, 2016 at 16:13 UTC | |
by v_melnik (Scribe) on Nov 13, 2016 at 20:11 UTC | |
by stevieb (Canon) on Nov 13, 2016 at 20:42 UTC | |
|
Re: Passing the logger's object (updated)
by haukex (Archbishop) on Nov 13, 2016 at 17:30 UTC | |
by v_melnik (Scribe) on Nov 13, 2016 at 20:05 UTC | |
by stevieb (Canon) on Nov 13, 2016 at 20:59 UTC | |
by haukex (Archbishop) on Nov 14, 2016 at 10:16 UTC | |
|
Re: Passing the logger's object
by stevieb (Canon) on Nov 13, 2016 at 21:21 UTC |