What's the point of beans?

后端 未结 6 1697
故里飘歌
故里飘歌 2020-12-20 11:36

I\'ve bean doing some JSP tutorials and I don\'t understand what the point of a bean class is. All it is, is get and set methods. why do we use them?

public          


        
6条回答
  •  囚心锁ツ
    2020-12-20 12:15

    I was reading JavaFX Properties and Binding there I got practically meaning of JavaBeans here is the paragraph.

    The Java programming language makes it possible to encapsulate data within an object, but it does not enforce any specific naming conventions for the methods that you define. For example, your code might define a Person class, which encapsulates a first name and a last name. But without naming conventions, different programmers might choose different names for these methods: read_first(), firstName(), getFN(), etc. would all be perfectly valid choices. However, there is no guarantee that these names will be meaningful to other developers.

    The JavaBeans component architecture addressed this problem by defining some simple naming conventions that bring consistency across projects. In JavaBeans programming, the full signatures for these methods would be: public void setFirstName(String name), public String getFirstName(), public void setLastName(String name), and public String getLastName(). This naming pattern is easily recognizable, both to human programmers and to editing tools, such as the NetBeans IDE. In JavaBeans terminology, the Person object is said to contain firstName and lastName properties.

    The JavaBeans model also provides support for complex property types, plus an event delivery system. It also contains a number of support classes, all available as an API under the java.beans package. Therefore, mastering JavaBeans programming involves learning the required naming conventions and its corresponding API. (For more background reading on JavaBeans in general, see the JavaBeans lesson of the Java Tutorial).

提交回复
热议问题