Constructors: Still your friend

In the new world of frameworks and dependency injection, objects are typically constructed "empty" and have a series of initialization calls made to them, and often (in Java) a series of disposal calls.

This initialization can't really happen independent of the framework. You lose the flexibility of using your code without the framework. (Generally speaking, anything "really interesting" in your code should be independent of the framework, so usually this isn't a great loss.) But frameworks (usually) ask you to violate a fundamental principle of OOP: Which is successfully constructed objects should be fully functional.

A common "code smell" you run into often is when you try to use an object but have to do 3-4 method calls to even use it, e.g. "setX" "setY" and run "init" or "start". It's not onerous to require this but developers are horribly lazy and will use your class "wrong" the first few times and curse you and your family.

Web Beans allows for multiple styles of injection. Luckily, and unlike Seam on which it is based, it supports an @Initializer annotation for injecting dependencies when creating components. This is annotation is used on a construction and allows for immutable objects as well. This style of injection is borrowed from Google Guice.

(Web Beans, is summarized thusly: A combination of Guice, JSF, Java EL, and Seam for Java EE.)

Read and post comments | Send to a friend

Advertisements

About eliasross

Blogging before the word "blog" was invented.
This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s