Umesh Kacha
Umesh Kacha

Reputation: 13666

Is it possible to use Google Guice on existing Java Swing code of around 15k?

We are trying to make our code decoupled and came across this Guice. It seems best choice. I have not used it.

My doubt is can we use it in existing production code which is aroung 15k lines? I mean how much effort do we need to achieve this? Is it right way to do it? or Need to write up entire code base with GUICE.

Any idea?

Upvotes: 0

Views: 389

Answers (4)

AlexR
AlexR

Reputation: 115328

It depends on how good is your code. If it is well designed, e.g. there are logical modules, all implementations have clear interfaces and you are using factories to create objects it is easier.

Anyway I'd recommend you incremental approach, i.e. refactor your application module-by-module.

Upvotes: 0

Martijn Verburg
Martijn Verburg

Reputation: 3305

So you want to introduce Dependency Injection? Yes Guice is a good lightweight container to start with. I'd begin by identifying where you're going to gain the most benefit in using DI (e.g. It sounds like you have some decoupling concerns). Your number of lines of code is irrelevant.

It's a good idea to introduce Guice/DI little bits at a time (I'd use a TDD approach), constructor/setter injection is the easiest place to start.

Upvotes: 2

Boris Pavlović
Boris Pavlović

Reputation: 64622

Yes, it's possible. You don't have to do a rewrite. Introduce the tool and slowly replace few direct references with injections, see how it works and continue. After some time you'll gain confidence and replace most of the constructor calls with Guice injections.

Upvotes: 2

Mirek Pluta
Mirek Pluta

Reputation: 8003

If you used dependency injection properly in your code, then introducing guice to a project will be easy. If you've got singletons used all over the code, you'd have to remake it a bit. Notice, that code doesn't rely on anything from guice library.

A year ago I introduced a guice when project was already a big complex, containing static references to singletons etc, anyway it wasn't such hard to do that change.

Upvotes: 0

Related Questions