2

Philosophical Question:

An issue that occurred to me is that especially when using frameworks like Spring or Hibernate ( which are everywhere in industry), we have annotate everything.

This is better obviously then the declarative XML statements... but it also means that we are engaging in declarative programming since the engine (framework) is taking care of doing something for us. The engine itself may be written in Java (OOP), but we are essentially programming using declarations.

E.g. @Autowire - Inject my Component here, I don't care how you do it or what goes on in the background.

So is this development through annotations herecy? Or is it just the same thing as using configuration files (XML and properties).

Background Information:

"Declarative Programming in Java" - http://www.onjava.com/pub/a/onjava/2004/04/21/declarative.html

Menelaos
  • 267

1 Answers1

4

I see no fundamental incompatibility between annotations or OOP. Annotations can be declarative (e.g. @Nullable - 'this thing has such and such properties'), which is not different from what interfaces or type systems do. Or they can define wiring/IOC (e.g. @Autowire) - which is built on top of OOP concepts in the first place.

Which isn't to say that annotations are always good - you can misuse them.

In particular, having 'hard coded' wiring with annotations ('give me that particular instance of an object') is no different (and no better) than a 'new': a tight coupling between two objects, and a code smell.

Code wisely.

ptyx
  • 5,871