POJO>JavaBean

  • https://www.javatpoint.com/pojo-in-java
  • https://www.baeldung.com/java-pojo-class 非常推荐这一篇,从POJO引出为什么出现JavaBean

When we talk about a POJO, what we’re describing is a straightforward type with no references to any particular frameworks. A POJO has no naming convention for our properties and methods.

Below are some properties of the POJO class:

  • The POJO class must be public.
  • It must have a public default constructor.
  • It may have the arguments constructor.
  • All objects must have some public Getters and Setters to access the object values by other Java Programs.
  • The object in the POJO Class can have any access modifies such as private, public, protected. - But, all instance variables should be private for improved security of the project.
    A POJO class should not extend predefined classes.
  • It should not implement prespecified interfaces.
  • It should not have any prespecified annotation.

But, we aren’t following any real convention for constructing, accessing, or modifying the class’s state.
This lack of convention causes two problems:
First, it increases the learning curve for coders trying to understand how to use it.
Second, it may limit a framework’s ability to favor convention over configuration, understand how to use the class, and augment its functionality.
To explore this second point, let’s work with EmployeePojo using reflection. Thus, we’ll start to find some of its limitations.

A JavaBe

an is still a POJO but introduces a strict set of rules around how we implement it:

  • Access levels – our properties are private and we expose getters and setters
  • Method names – our getters and setters follow the getX and setX convention (in the case of a boolean, isX can be used for a getter)
  • Default Constructor – a no-argument constructor must be present so an instance can be created without providing arguments, for example during deserialization
  • Serializable – implementing the Serializable interface allows us to store the state

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值