Hi all;
just carefully taking my first steps in the Spring environment, so far I'm impressed by the functionality it provides, even though I don't have no idea so far how long it will take to at least slightly understand and get along with all that's possible in the Spring environment.
At the moment, I am playing around a little, reading through tutorials and working through some examples, being left with my first question (of which I don't know whether it's a matter of missing understanding of how Spring works or some basic lack of Java knowledge):
I am into building a very basic Notes implementation, currently using two interfaces:
- "Note" as the interface to access a very note - getTitle(), getContent(), getDate() and the like,
- "NotesList" as a List to keep track of notes - getNote(), addNote(), removeNote(), ...
Each of those is currently implemented by a very basic class named "MemoryBasedNote" (basically an object storing properties in private variables) and "MemoryBasedNotesList" (the same - all notes stored in an ArrayList).
A "NotesManager" class is supposed to handle this mess. This one has a setNotesList() function and recieves the MemoryBasedNotesList implementation via Dependency Injection. So far, so good.
Now, I want to add a new note from within NotesManager. Usually, I'd do something like
Note newNote = new Note(...);
this.notesList.addNote(newNote);
My problem, right now is: Using Spring and not wanting to hardcode any dependencies, I don't want to do
MemoryBasedNote newNote = ...
but want NotesManager to use an implementation of the Notes interface according to configuration. How to do that? Basically, how can I create a new instance while just knowing about an interface and not the very class to implement this? Can this be done using Dependency Injection (something like "setNotesImplementation()")? Is there a better way? Is this a stupid idea after all?
Thanks for any hints (and for reading this far).
Cheers,
Kris![]()


Reply With Quote
Actually, took some time getting used to it, but I guess once you got it, you don't want to work without it anymore... 