‎2021 Jul 08 7:40 AM
Hello All,
I have a requirement where i need to create instance of singleton class and after that delete it and recreate instance which another parameter.
can you please suggest how i can do that.
thanks
‎2021 Jul 08 7:57 AM
First thing, you cannot delete an instance in ABAP (for human abaper)
So your only solution is to clear the "variable" containing the reference to the instance.
and it depends of your code, but it is certainly available in the my_class=>get_instance( ).
(you have to create my_class=>delete_instance)
just a question, why do you use singleton if you clear the instance after use it ??
‎2021 Jul 08 8:20 AM
If you need to delete the instance, then it shouldn't be a singleton class.
‎2021 Jul 08 8:33 AM
Maybe the singleton as you implemented it is the wrong solution.
Is there the requirement to delete an instance and recreate with the SAME parameters?
My idea is to keep one instance per parameter combination.
But: if you don't need the instance any more at all you should not buffer it.
‎2021 Jul 08 8:35 AM
Hello,
i want to create instance with different parameters but not able to do that as it is saying instance is already created.
Thanks
Mahesh
‎2021 Jul 08 9:26 AM
‎2021 Jul 08 9:58 AM
raymond.giuseppi his requirement is to have a singleton depending of parameters, so it could be a multiton
‎2021 Jul 08 10:07 AM
‎2021 Jul 08 10:10 AM
‎2021 Jul 08 10:11 AM
‎2021 Jul 08 10:41 AM
Clean ABAP suggests only using singletons when you really need them. I used to use them a lot, but they're not usually necessary in ABAP.
‎2021 Jul 08 12:18 PM
I use them a lot for User-exit.
And I think in Clean-Pattern-Code you should use factory to manage the Multi or Single ton
‎2021 Jul 08 12:22 PM
raymond.giuseppi I am not agree with you.
Last time I used the multitone was for item in sales order in several user-exit / enhancement / badi ... (big big project). Each item need to have separated memory / behaviour. This is not related to performance.