java - Are there patterns for model / entity classes -


what best approach take when pulling model objects multiple datasources?

for example have application has has data stored in mysql database using hibernate. if wanted store other objects in ec2 or google app engine? understand dao's abstract implementation of working particular data source, entities themselves?

at first thought annotating entities jpa annotations great solution, seems i've tied entities down particular implementation. in case of app engine example, of these annotations make no sense.

it seems need pure pojo class represent entities, entirely free of persistence logic. if wanted model dog example (yes lame choice, whatever).
make sense have abstract dog class, define subclasses work particular persistence solutions: hibernatedog, gaedog, etc.

thanks.

this great question, if issue isn't new. industry, we've been changing "conventional wisdom" on subject on years. answers today aren't you'd 5 years ago or 5 years in future.

in picturing how i'd handle item, i'm wondering things haven't stated: app "system of record" dog entities? other subsystems/layers/apps need know dog entities.

in java, when write brand new types animal > dog, following reward: opportunity write whole bunch more code knows how interact animal objects , dog objects. i'm less convinced in 2010 idea 5 years ago.

are responsible designing database dog information stored? used time, nowadays find myself integrating data records managed other systems: google apis, ldap entities, data warehouses, products peoplesoft, etc.

if you're not in charge of defining dog , how interact universe, i'd @ domain-agnostic way model dog information in memory. there tons: xml/dom, json, map, etc.

the advantages of moving other people's data around in these formats many...

  • you don't have write pojos
  • these rich in features, documentation, , testing
  • there numerous existing apis transform, manipulate, , serialize these creatures
  • you might reuse view/controller/other code across other domains

on other hand... if system of record dog data, consider using interfaces instead of abstract classes. or perhaps interfaces and abstract classes. java has single inheritance; tie view/controller/other code interfaces guarentee future flexibility.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -