David Caroseli | Java Annotation Processors And Domain Model Objects
Spiegherò brevemente cos'è un Annotation Processor e come può essere usato per farci risparmiare molto tempo ed avere del codice altamente efficiente. Gli oggetti del modello di dominio sono solitamente delle classi Java con funzionalità standard che sono semplici quanto noiose da scrivere e da tenere aggiornate. I processori di annotazioni possono esserci utili per automatizzare questo processo ed avere del codice sempre aggiornato e non dover rinunciare all'efficienza.
Java annotation processors - Roma Android User Group #1
1. +
Davide Caroselli, CTO at Pubster
davide@pubsterapp.com
Java Annotation
Processors &
Domain Model
Objects
2. +
Domain Model Objects
Pub
Deal
PubsterLite Domain Model
• ID [long]
• Name [String]
• Address [String]
• Latitude [double]
• Longitude [double]
• ID [long]
• Name [String]
• Coins [int]
• Type [long]
3. +
Coding…
n Getter methods
n Setter methods
n JSON serialization and deserialization methods
n Parcelable serialization and deserialization methods
n …
FOR EACH DOMAIN MODEL CLASS !
4. +
Java Reflection
n Easy to use
n Its behaviour can be
customized
n It works!
n Bad performances
n Not ALL the code could be
automatized (getter and setter)
n Could not be used for every
task, or for very specific
implementation logic
PRO CONS
6. +
Java Annotation Processor
CODENAME: Automagically!
n Annotations
n “Mark” the code in a given point to attach a sort of meta-
data that the Java Compiler or Runtime Environment can
parse and use.
n Java Annotation Processor
n A processor that run at compile-time and could add brand
new source files to the build. It can “read” the Annotations
in the code.
8. +
Want more?
n Any model-level common logic methods
(normalization, validation…)
n SQLite serialization and deserialization
methods
n Maybe lazy load getter and setter ?
n Fetch objects when you need to!