Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38723
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: How to make my library independent using DI |
| Date | 2019-02-01 14:13 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrnq58kvi.k8o.avl@logic.at> (permalink) |
| References | <c9bc00ee-744c-49e2-b026-08a68841cf48@googlegroups.com> <slrnq52u2s.k8o.avl@logic.at> <e09b44b3-55fd-4dc9-a16c-156e1bd4fff8@googlegroups.com> |
mike <mikaelpetterson@hotmail.com> wrote: > I need to create an instance of AHelper, in the application using the library, > and inject it into my lib. Otherwise I will not be able to access the data from > version() and productNumber(). > I mean shall I call: > MyDataClassImpl( new AHelper()) from the application? That's surely the most straightforward thing to do. There might be other options (even as ugly as involving static fields - don't do that, unless the application really only needs a single instance for the whole VM) > And at what point in time should this be done. Apparently exactly when you need the instance of MyDataClassImpl if more classes of the library need a reference to an > And if the MyDataClassImpl needs more external data, let's say > from BHelper() also, do add the following in my app: > MyDataClassImpl(new AHelper(),new BHelper()) ? If the new data is *necessary* you just add new methods to the interface in the lib, and it will require other applications to upgrade along with the lib (or stick to older versions of the lib) If you're on Java8 or newer, and if it makes sense, you might add default-implementations to the interface for the new methods, so the lib will remain compatible with old apps, (but not with Java7 or older, then) Different helpers (imho) only make sense, if they cover different parts of the library, and aren't always necessary at the same time.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to make my library independent using DI mike <mikaelpetterson@hotmail.com> - 2019-01-29 10:11 -0800
Re: How to make my library independent using DI Martin Gregorie <martin@mydomain.invalid> - 2019-01-29 19:29 +0000
Re: How to make my library independent using DI Andreas Leitgeb <avl@logic.at> - 2019-01-30 10:11 +0000
Re: How to make my library independent using DI mike <mikaelpetterson@hotmail.com> - 2019-01-30 06:13 -0800
Re: How to make my library independent using DI Andreas Leitgeb <avl@logic.at> - 2019-02-01 14:13 +0000
Re: How to make my library independent using DI Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-02-04 16:33 +0100
csiph-web