What's the point of beans?

后端 未结 6 1725
故里飘歌
故里飘歌 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:04

    1. A Bean obtains all the benefits of Java's "write-once, run-anywhere" paradigm. The properties, events, and methods of a Bean that are exposed to an application builder tool can be controlled.

    2. A Bean may be designed to operate correctly in different locales, which makes it useful in global markets.

    3. Auxiliary software can be provided to help a person configure a Bean. This software is only needed when the design-time parameters for that component are being set. It does not need to be included in the run-time environment. The configuration settings of a Bean can be saved in persistent storage and restored at a later time.

    4. A Bean may register to receive events from other objects and can generate events that are sent to other objects.

      • Advantages of Bean

    The use of scriptlets (those <% %> things) is indeed highly discouraged since the birth of taglibs (like JSTL) and EL (Expression Language, those ${} things) over a decade ago. The major disadvantages of scriptlets are:

    1. Reusability: you can't reuse scriptlets.

    2. Replaceability: you can't make scriptlets abstract.

    3. OO-ability: you can't make use of inheritance/composition.

    4. Debuggability: if scriptlet throws an exception halfway, all you get is a blank page.

    5. Testability: scriptlets are not unit-testable.

    6. Maintainability: per saldo more time is needed to maintain mingled/cluttered/duplicated code logic.

      • Check Whole...BalusC's answer here

提交回复
热议问题