terminology - What does the term Plain Old Java Object (POJO) exactly mean? -


what term plain old java object (pojo) mean? couldn't find explanatory enough.

pojo's wikipedia page says pojo ordinary java object , not special object. now, makes or doesn't make , object special in java?

the above page says pojo should not have extend prespecified classes, implement prespecified interfaces or contain prespecified annotations. mean pojos not allowed implement interfaces serializable, comparable or classes applets or other user-written class/interfaces?

also, above policy (no extending, no implementing) means not allowed use external libraries?

where pojos used?

edit: more specific, allowed extend/implement classes/interfaces part of java or external libraries?

plain old java object name used emphasize given object ordinary java object, not special object such defined ejb 2 framework.

class {}
class b extends/implements c {}

note: b non pojo when c kind of distributed framework class or ifc. e.g. javax.servlet.http.httpservlet, javax.ejb.entitybean or j2ee extn , not serializable/comparable. since serializable/comparable valid pojo.

here simple object independent. b special obj since b extending/implementing c. b object gets more meaning c , b restrictive follow rules c. , b tightly coupled with distributed framework. hence b object not pojo definition.

code using class object reference not have know type of it, , can used many frameworks.

so pojo should not have 1) extend prespecified classes , 2) implement prespecified interfaces.

javabean example of pojo serializable, has no-argument constructor, , allows access properties using getter , setter methods follow simple naming convention.

pojo purely focuses on business logic , has no dependencies on (enterprise) frameworks. means has code business logic how instance created, service(ejb..) object belongs , special characteristics( stateful/stateless) has decided frameworks using external xml file.

example 1: jaxb service represent java object xml; these java objects simple , come default constructor getters , setters.

example 2: hibernate simple java class used represent table. columns instances.

example 3: rest services. in rest services have service layer , dao layer perform operations on db. dao have vendor specific queries , operations. service layer responsible call dao layer perform db operations. create or update api(methods) of dao take pojos arguments, , update pojos , insert/update in db. these pojos (java class) have states(instance variables) of each column , getters , setters.

in practice, people find annotations elegant, while see xml verbose, ugly , hard maintain, yet others find annotations pollute pojo model. thus, alternative xml, many frameworks (e.g. spring, ejb , jpa) allow annotations used instead or in addition xml:

advantages:
decoupling application code infrastructure frameworks 1 of many benefits of using pojos. using pojos future proofs application's business logic decoupling volatile, evolving infrastructure frameworks. upgrading new version or switching different framework becomes easier , less risky. pojos make testing easier, simplifies , accelerates development. business logic clearer , simpler because won't tangled infrastructure code

references : wiki source2


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -