11

Click here to load reader

Java annotation processors - Roma Android User Group #1

  • Upload
    bemyapp

  • View
    573

  • Download
    3

Embed Size (px)

DESCRIPTION

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.

Citation preview

Page 1: Java annotation processors  - Roma Android User Group #1

+

Davide Caroselli, CTO at Pubster [email protected]

Java Annotation Processors &

Domain Model Objects

Page 2: Java annotation processors  - Roma Android User Group #1

+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]

Page 3: Java annotation processors  - Roma Android User Group #1

+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 !

Page 4: Java annotation processors  - Roma Android User Group #1

+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

Page 5: Java annotation processors  - Roma Android User Group #1

+Java Annotation Processor CODENAME: Automagically!

Page 6: Java annotation processors  - Roma Android User Group #1

+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.

Page 7: Java annotation processors  - Roma Android User Group #1

Demo

Page 8: Java annotation processors  - Roma Android User Group #1

+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!

Page 9: Java annotation processors  - Roma Android User Group #1

Want EVEN more ?

Page 10: Java annotation processors  - Roma Android User Group #1

+iOS or Windows Phone Domain Model Class

Page 11: Java annotation processors  - Roma Android User Group #1

WE ARE HIRING SEND YOUR CURRICULUM TO

[email protected]