Why should I use createComponent instead of creating the instance myself?

后端 未结 1 451
失恋的感觉
失恋的感觉 2020-12-18 01:35

This is more of a conceptual question.

I had to work on a functionality that had to create a dynamic h:dataTable. And whenever I created a component, I

相关标签:
1条回答
  • 2020-12-18 02:23

    The Application#createComponent() adds an extra abstract layer allowing runtime polymorphism and pluggability. The concrete implementation is configurable by <component> entry in faces-config.xml which could in turn be provided via a JAR. This allows changing implementation without rewriting/recompiling the code.

    It's exactly like as how JDBC API works: you don't do new SomeDriver(), but you do Class.forName(someDriverClassName) which allows the driver to not be a compiletime dependency and thus your JDBC code to be portable across many DB vendors without rewriting/recompiling.

    However, if the application is for "internal usage" only and not intented to be distributable (and thus all the code is always full under you control), then runtime polymorphism has not a so big advantage and may add (very minor) overhead.

    See also:

    • What is the relationship between component family, component type and renderer type?
    0 讨论(0)
提交回复
热议问题