Search code examples
javaatg

What is the purpose of Dynamic Bean in ATG


I've read documentation, but there is no definition of the main purpose of Dynamic Bean. I understand how to implement this but dont know why this approach so good.

So could someone tell the situation when it's good to use Dynamic Bean?

Thanks


Solution

  • Dynamic beans typically allow you to get and set fields which may not be explicit members. The most direct comparison is a map - maps allow you to get and set fields without defining them beforehand. However, a dyanamic bean conforms to standard java idioms (getters/setters).

    Unlike a hashmap, however, dyanbeans can enforce constraints more readily (and they hide the underlying data structure implementation, so they can be lazy, or make data connections when being set, etc... ) . For example, you can easily add a getter or setter to your dynabean that is explicit, and the code would read very idiomatically and cleanly interact with other bean apis.

    public int getCost()
    { 
        if(this.get("cost")==null)
         return -1;
        return Integer.parseInt(super.get("cost"));
    }