Hi,
Is it good to use object varaible?
For example:
Object classTest;
If(_variable) // assume it's defined
{
classTest = new ClassChild();
}
else
{
classTest = new ClassParent();
}
Where ClassChild extends ClassParent
Can i use it or shall i use anyType instead or is there another better way to achieve what i want?
Another way is to use Switch statement in construct method of Parent class, you can find many example in standard. This is what we have used in our customizations.
Public static ParentClass construct(VariableType _variable) { ParentClass class; switch(_variable) { case 'A': class = new childClass1(_variable); break; case 'B': class = new childClass2(_variable); break; } }
It's just an additional step. Nothing difference in that. Code I have written, and your code will work in the same way. I just provide another way of creating object for the class.
Thanks,
Girish S.
Hi Girish,
My code is already working but i wanted to ask if there is another better way.
May i know why u think using DictClass and makeObject is better than my way?
And what is DictClass and what it does?
Hi juniorAx,
You can use object class but i think it needs to do something like below.
Object classTest; DictClass className; If(_variable) // assume it's defined { className = new DictClass(className2Id('ChildClass')); classTest = className.makeObject(); } else { className = new DictClass(className2Id('ClassParent')); classTest = className.makeObject(); }
Thanks,
Girish S.
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,817
Most Valuable Professional
nmaenpaa
101,156