Ex 08 Task2

dummdidumm
Windoof-User
Windoof-User
Beiträge: 39
Registriert: 28. Apr 2010 18:49

Ex 08 Task2

Beitrag von dummdidumm »

I have a question regarding subtask b) from task 2. It says we should remove hardcoded dependencies and inject them through constructors. From looking at a code, I can see such a hardcoded dependency only in the DefaultEmailer. Afterwards, we should provide an UML-diagram which I don't understand because we only change the type of dependency (hardcoded vs injected) and not the dependencies itself. So nothing would change in the UML-diagram, what's the point in drawing one then?

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Ex 08 Task2

Beitrag von sproksch »

What are the current dependencies of the DefaultEmailer?

dummdidumm
Windoof-User
Windoof-User
Beiträge: 39
Registriert: 28. Apr 2010 18:49

Re: Ex 08 Task2

Beitrag von dummdidumm »

Ok if I understand that correctly, the small but important change in the UML is that after the refactoring we are dependant on interfaces and not concrete instances anymore and should show that in the diagram (I hope this is not too much of a giveaway of the solution, if it is correct).

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Ex 08 Task2

Beitrag von sproksch »

Yes, when thinking about extendability it would be a very important change to the design, if you could inverse the dependencies, wouldn't it? ;)

fbussjor
Erstie
Erstie
Beiträge: 12
Registriert: 31. Aug 2011 23:07

Re: Ex 08 Task2

Beitrag von fbussjor »

About e)
In the example unit test's guice was used for instantiating the SUT. I hope we are not limited to it and can also use the builder or even the good old manual wiring?

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Ex 08 Task2

Beitrag von sproksch »

The Guice test should simply serve as an example how to use Guice. There are three classes in the default package, which contain a main() method... I think it would be easiest if you use those three for the manual/builder/guice startup.

pabloarias
Erstie
Erstie
Beiträge: 15
Registriert: 1. Okt 2009 09:05

Re: Ex 08 Task2

Beitrag von pabloarias »

I'm a bit confused about the Emailer reference that I have to give to the TextEditor's constructor. When I try to make the dependency injection, I realize that I just can't pass in the Emailer's constructor a TextEditor reference as parameter, since I can't instantiate A TextEditor without the corresponding Emailer object, does somebody have a tip for me about what I should do here?

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Ex 08 Task2

Beitrag von sproksch »

So what is your concrete problem?

edit: Ah ok... you are working on the "do it manually" subtask?

pabloarias
Erstie
Erstie
Beiträge: 15
Registriert: 1. Okt 2009 09:05

Re: Ex 08 Task2

Beitrag von pabloarias »

yes I'm on the do-it-manually

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Ex 08 Task2

Beitrag von sproksch »

You could think about introducing a setter method to resolve the circular dependency.

pabloarias
Erstie
Erstie
Beiträge: 15
Registriert: 1. Okt 2009 09:05

Re: Ex 08 Task2

Beitrag von pabloarias »

Yes, I already made that, it seems to work for the do-it-manually task, but in the guice task I still have a little problem:
After binding the interfaces of the Emailer to the actual implementation with bind(...).to(...); I have to, somehow, bind the TextEditor used by the Emailer to an EnglishTextEditor: bind(TextEditor.class).toInstance(new EnglishTextEditor(??)), I just don't know how to get the instance of the created Emailer above. I hope I do explain myself.

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Ex 08 Task2

Beitrag von sproksch »

Perhaps binding to an instance is not the right thing to do here? ;)

pabloarias
Erstie
Erstie
Beiträge: 15
Registriert: 1. Okt 2009 09:05

Re: Ex 08 Task2

Beitrag von pabloarias »

Ohh yes off course! I can't believe I didn't see that... I'm not having a good day my dog died today :cry:

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Ex 08 Task2

Beitrag von sproksch »

I'm very sorry to hear that.

Antworten

Zurück zu „Archiv“