Why we use Constant ?

Certified Associate Developer

Hi everyone, 

 Can anyone explain the purpose of using constant ? I know that constant is literal values, and it can be resued in multiple objects. Is there any purpose of using constant ? Moreover, when we will create constant in application ?

Thanks!

  Discussion posts and replies are publicly visible

Parents
  • Certified Senior Developer

    1.suppose you are providing  Gender (1.Male 2.Female) in 10 form interfaces, so you don't have to hard code every time just create a constant and use it as value in all forms .

    2.for same example , if in future you want add one more gender as (3.Others) so if you have used constant you have to update only your constant and the gender will be updated in all 10 form interfaces, if you don't use Constant in these type of scenarios you have to change gender manually in all 10 forms.

Reply
  • Certified Senior Developer

    1.suppose you are providing  Gender (1.Male 2.Female) in 10 form interfaces, so you don't have to hard code every time just create a constant and use it as value in all forms .

    2.for same example , if in future you want add one more gender as (3.Others) so if you have used constant you have to update only your constant and the gender will be updated in all 10 form interfaces, if you don't use Constant in these type of scenarios you have to change gender manually in all 10 forms.

Children
No Data