POJO LÀ GÌ

  -  
I"m not sure about the difference. I"m using Hibernate and, in some books, they use JavaBean và POJO as an interchangeable term. I want khổng lồ know if there is a difference, not just in the Hibernate context, but as general concepts.

Bạn đang xem: Pojo là gì

quý khách vẫn xem: Java — thuật ngữ plain old java object ( pojo là gì, java pojo là gì


*

*

A JavaBean follows certain conventions. Getter/setter naming, having a public mặc định constructor, being serialisable etc. See JavaBeans Conventions for more details.

A POJO (plain-old-Java-object) isn"t rigorously defined. It"s a Java object that doesn"t have a requirement to lớn implement a particular interface or derive sầu from a particular base class, or make use of particular annotations in order to be compatible with a given framework, và can be any arbitrary (often relatively simple) Java object.

Share Improve sầu this answer Follow edited Apr 30 "16 at 23:16 answered Sep 8 "09 at 14:18
*

Brian AgnewBrian Agnew 252k3636 gold badges314314 silver badges423423 bronze badges 8 | Show 3
more comments 107All JavaBeans are POJOs but not all POJOs are JavaBeans.

A JavaBean is a Java object that satisfies certain programming conventions:

the JavaBean class must implement either Serializable or Externalizable;the JavaBean class must have sầu a public no-arg constructor;all JavaBean properties must have sầu public setter và getter methods (as appropriate);all JavaBean instance variables should be private. Share Improve sầu this answer Follow edited Sep 8 "17 at 6:39
*

Manu Manjunath 5,36211 gold badge2929 silver badges3030 bronze badges answered Jul 22 "14 at 11:52
*

nagapavannagapavan 1,07111 gold badge77 silver badges22 bronze badges 3 Add a phản hồi | 25According to Martin Fowler a POJO is an object which encapsulates Business Logic while a Bean (except for the definition already stated in other answers) is little more than a container for holding data và the operations available on the object merely mix & get data.

The term was coined while Rebecca Parsons, Josh MacKenzie và I were preparing for a talk at a conference in September 2000. In the talk we were pointing out the many benefits of encoding business lô ghích inlớn regular java objects rather than using Entity Beans. We wondered why people were so against using regular objects in their systems & concluded that it was because simple objects lacked a fancy name. So we gave sầu them one, và it"s caught on very nicely.

http://www.martinfowler.com/bliki/POJO.html

Share Improve this answer Follow answered Oct 12 "15 at 7:23 SphygmomanometerSphygmomanometer 56555 silver badges1010 bronze badges Add a comment | 9Pojo - Plain old java object

pojo class is an ordinary class without any specialties,class totally loosely coupled from technology/framework.the class does not implements from technology/framework & does not extends from technology/framework api that class is called pojo class.

pojo class can implements interfaces and extover classes but the super class or interface should not be an technology/framework.

Examples :

1.

class ABC----ABC class not implementing or extending from technology/framework that"s why this is pojo class.

class ABC extends HttpServlet---ABC class extending from servlet technology api that"s why this is not a pojo class.

Xem thêm: Quận Thủ Đức Có Gì Chơi Giải Trí Lý Tưởng Nhất Tại Thủ Đức, Chơi Gì Ở Tp Thủ Đức

3.

class ABC implements java.rmày.Remote----ABC class implements from rngươi api that"s why this is not a pojo class.

4.

class ABC implements java.io.Serializable---this interface is part of java language not a part of technology/framework.so this is pojo class.

5.

class ABC extends Thread--here thread is also class of java language so this is also a pojo class.

6.

class ABC extends Test--if Test class extends or implements from technologies/framework then ABC is also not a pojo class because it inherits the properties of Test class.if Test class is not a pojo class then ABC class also not a pojo class.

7.

Xem thêm: Game Bắn Trứng Cổ Điển Chơi, Dynomite Game Bắn Trứng Kinh Điển

now this point is an exceptional case

Entityclass ABC--Entity is an annotation given by hibernate api or jpage authority api but still we can hotline this class as pojo class.class with annotations given from technology/framework is called pojo class by this exceptional case.