Plain old Java object: Difference between revisions

Content deleted Content added
m Remove links to pages that direct to this page
m oops, fix duplicate ref
 
(2 intermediate revisions by 2 users not shown)
Line 1:
{{Short description|Type of object in Java programming language}}
In [[software engineering]], a '''plain old Java object''' ('''POJO''') is an ordinary [[Java (programming language)|Java]] [[object (computer science)|object]], not bound by any special restriction. The term was coined by [[Martin Fowler (software engineer)|Martin Fowler]], Rebecca Parsons and Josh MacKenzie in September 2000:<ref name="bliki">{{cite web |url=http://www.martinfowler.com/bliki/POJO.html |title=MF Bliki: POJO |work=MartinFowler.com }}</ref>
 
<blockquote>
"{{blockquote|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."<ref name="bliki">{{cite web |url=http://www.martinfowler.com/bliki/POJO.html |title=MF Bliki: POJO |work=MartinFowler.com }}</ref>
</blockquote>
 
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|date=April 2013}}
Line 40 ⟶ 39:
The definition of the POJO can be as follows:
 
<syntaxhighlight lang="java">public class MyBean {
public class MyBean {
 
private String someProperty;
Line 52 ⟶ 50:
this.someProperty = someProperty;
}
}</syntaxhighlight>
}
</syntaxhighlight>
 
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.
 
The [https://projectlombok.org/ lombok] library allows to change the code dynamically to integrate those conventions without the hassle to write them. The following code would generate the same bean, with the addition of an empty constructor :<syntaxhighlight lang="java">@NoArgsConstructor
public class MyBean {
 
@Getter @Setter
private String someProperty;
 
}</syntaxhighlight>Other libraries or framework generate code (or bytecode) with those conventions directly. The addition of those tools help alleviate the [[Boilerplate code|boilerplate]], which in turn reduces the bugs frequency and maintenance cost .
 
===Transparently adding services===