Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Definition  





2 Contextual variations  



2.1  JavaBeans  





2.2  Transparently adding services  







3 Related Acronyms  



3.1  Plain old Java Interface  







4 See also  





5 References  














Plain old Java object






العربية
Català
Deutsch
Español
Esperanto
Français

Interlingua
Italiano
עברית
Magyar
Bahasa Melayu

Polski
Português
Русский
Svenska
Українська
 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 

(Redirected from POJO)

Insoftware engineering, a plain old Java object (POJO) is an ordinary Java object, not bound by any special restriction. The term was coined by Martin Fowler, Rebecca Parsons and Josh MacKenzie in September 2000:[1]

"We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one, and it's caught on very nicely."[1]

The term "POJO" initially denoted a Java object which does not follow any of the major Java object models, conventions, or frameworks. It has since gained adoption as a language-agnostic term, because of the need for a common and easily understood term that contrasts with complicated object frameworks.[citation needed]

The term continues an acronym pattern to coin retronyms for constructs that do not use fancy new features:

Definition[edit]

Ideally speaking, a POJO is a Java object not bound by any restriction other than those forced by the Java Language Specification; i.e. a POJO should not have to

  1. Extend prespecified classes, as in
    public class Foo extends javax.servlet.http.HttpServlet { ...
    
  2. Implement prespecified interfaces, as in
    public class Bar implements javax.ejb.EntityBean { ...
    
  3. Contain prespecified annotations, as in
    @javax.persistence.Entity public class Baz { ...
    

However, due to technical difficulties and other reasons, many software products or frameworks described as POJO-compliant actually still require the use of prespecified annotations for features such as persistence to work properly. The idea is that if the object (actually class) were a POJO before any annotations were added, and would return to POJO status if the annotations are removed then it can still be considered a POJO. Then the basic object remains a POJO in that it has no special characteristics (such as an implemented interface) that makes it a "Specialized Java Object" (SJO or (sic) SoJO).

Contextual variations[edit]

JavaBeans[edit]

AJavaBean is a POJO that is serializable, has a no-argument constructor, and allows access to properties using getter and setter methods that follow a simple naming convention. Because of this convention, simple declarative references can be made to the properties of arbitrary JavaBeans. Code using such a declarative reference does not have to know anything about the type of the bean, and the bean can be used with many frameworks without these frameworks having to know the exact type of the bean. The JavaBeans specification, if fully implemented, slightly breaks the POJO model as the class must implement the Serializable interface to be a true JavaBean. Many POJO classes still called JavaBeans do not meet this requirement. Since Serializable is a marker (method-less) interface, this is not much of a burden.

The following shows an example of a JavaServer Faces (JSF) component having a bidirectional binding to a POJO's property:

<h:inputText value="#{MyBean.someProperty}"/>

The definition of the POJO can be as follows:

public class MyBean {

    private String someProperty;

    public String getSomeProperty() {
         return someProperty;
    }

    public void setSomeProperty(String someProperty) {
        this.someProperty = someProperty;
    }
}

Because of the JavaBean naming conventions the single "someProperty" reference can be automatically translated to the "getSomeProperty()" (or "isSomeProperty()" if the property is of Boolean type) method for getting a value, and to the "setSomeProperty(String)" method for setting a value.

Transparently adding services[edit]

As designs using POJOs have become more commonly used, systems have arisen that give POJOs the full functionality used in frameworks and more choice about which areas of functionality are actually needed. In this model, the programmer creates nothing more than a POJO. This POJO purely focuses on business logic and has no dependencies on (enterprise) frameworks. Aspect-oriented programming (AOP) frameworks then transparently add cross-cutting concerns like persistence, transactions, security, and so on.[6]

Spring was an early implementation of this idea and one of the driving forces behind popularizing this model.

An example of an EJB bean being a POJO:

The following shows a fully functional EJB bean, demonstrating how EJB3 leverages the POJO model:

public class HelloWorldService {

    public String sayHello() {
        return "Hello, world!";
    }
}

As given, the bean does not need to extend any EJB class or implement any EJB interface and also does not need to contain any EJB annotations. Instead, the programmer declares in an external XML file which EJB services should be added to the bean:

<enterprise-beans>
    <session>
        <ejb-name>helloWorld</ejb-name>
        <ejb-class>com.example.HelloWorldService</ejb-class>
        <session-type>stateless</session-type>
    </session>
</enterprise-beans>

In practice, some people find annotations elegant, while they see XML as verbose, ugly and hard to maintain, yet others find annotations pollute the POJO model.[7]

Thus, as an alternative to XML, many frameworks (e.g. Spring, EJB and JPA) allow annotations to be used instead of or in addition to XML. The following shows the same EJB bean as shown above but with an annotation added. In this case the XML file is no longer needed:

@Stateless
public class HelloWorldService {

    public String sayHello() {
        return "Hello, world!";
    }
}

With the annotation as given above the bean isn't a truly pure POJO anymore, but since annotations are merely passive metadata this has far fewer harmful drawbacks compared to the invasiveness of having to extend classes and/or implement interfaces.[6] Accordingly, the programming model is still very much like the pure POJO model.

Related Acronyms[edit]

Plain old Java Interface[edit]

A Plain old Java Interface (POJI) is a basic form of Java interface and acceptable at points where more complex Java interfaces are not permitted.[8]: 57, 572, 576, 579, 1340 

See also[edit]

References[edit]

  1. ^ a b "MF Bliki: POJO". MartinFowler.com.
  • ^ Almaer, Dion (2006-07-17). "Return of the POJO: Plain 'Ole JavaScript". Ajaxian. Archived from the original on 2014-09-13. Retrieved 2014-08-19.
  • ^ "POCO Support". microsoft.com. Retrieved 2012-05-27.
  • ^ Kneschke, Jan (2007-02-19). "typesafe objects in PHP". kneschke.de. Archived from the original on 2012-03-26. Retrieved 2012-05-27.
  • ^ Cheong, Jym (2011-06-26). "Controller with bare-bone Plain Old PHP Object aka POPO". jym.sg. Archived from the original on 2012-03-26. Retrieved 2012-05-27.
  • ^ a b Martin, Robert C; (2008); Clean Code, Chapter 11, Pure Java AOP Frameworks
  • ^ Panda, Debu; Rahman, Reza; Lane, Derek; (2007). EJB 3 in action, Manning Publications Co., Shelter Island (NY), ISBN 978-1-93-398834-4 (www.manning.com/books/ejb-3-in-action). Chapter 11, Deployment descriptors vs. annotations
  • ^ Wahli, Ueli; Vieira, Miguel; Gomes, Ferreira Lopes; Hainey, Brian; Moharram, Ahmed; Napoli, JuanPablo; Rohr, Marco; Cui, Henry; Gan, Patrick; Gonzalez, Celso; Ugurlu, Pinar; Ziosi, Lara (29 June 2009). Rational Application Developer V7.5 Programming Guide. IBM Redbooks. ISBN 978-0738432892.

  • Retrieved from "https://en.wikipedia.org/w/index.php?title=Plain_old_Java_object&oldid=1219064986"

    Categories: 
    Java (programming language)
    Computer jargon
    Hidden categories: 
    Articles with short description
    Short description matches Wikidata
    All articles with unsourced statements
    Articles with unsourced statements from April 2013
     



    This page was last edited on 15 April 2024, at 14:52 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki