Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Delete instance of singleton class

mahesh_jagnani
Participant
0 Likes
4,815

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

12 REPLIES 12
Read only

FredericGirod
Active Contributor
4,180

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 ??

Read only

matt
Active Contributor
4,180

If you need to delete the instance, then it shouldn't be a singleton class.

Read only

BiberM
Contributor
0 Likes
4,180

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.

Read only

0 Likes
4,180

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

Read only

0 Likes
4,180

So you need to convert your Singleton to MultiTon

Read only

FredericGirod
Active Contributor
4,180

raymond.giuseppi his requirement is to have a singleton depending of parameters, so it could be a multiton

Read only

RaymondGiuseppi
Active Contributor
0 Likes
4,180

Sorry, but your requirement is at least paradoxical (does not really make sense)

Is this a standad class or a customer one, in second case convert it to a normal class (with non private constructor)

Read only

RaymondGiuseppi
Active Contributor
Read only

RaymondGiuseppi
Active Contributor
0 Likes
4,180

frdric.girod multiton is useful for performance, reusability, if OP doesn't use same parameter twice, I would rather suggest a classic standard class.

Read only

matt
Active Contributor
0 Likes
4,180

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.

Read only

FredericGirod
Active Contributor
0 Likes
4,180

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

Read only

FredericGirod
Active Contributor
0 Likes
4,180

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.