Single instance of class

71 次查看(过去 30 天)
Hello all! I have just started learning MATLAB and am exploring the OOPS concepts in it. Can someone guide me how to create a class and limit it with only one instance? Also can someone tell me where one can use it

采纳的回答

Chirag Nighut
Chirag Nighut 2019-7-4
In order to limit a single instance of a class you can use the persistent variables. Such type of classes are called Singleton Class. Such classes can be used
  1. When you wish to create a single client for connecting a server.
  2. Handle for a GUI
Following link should help you understand the singleton class and also its implementation:
  1 个评论
Andreas Justin
Andreas Justin 2024-2-20
编辑:Andreas Justin 2024-2-20
The persistent variables will be reinstantiated if you change the code of a class containing said variables. Even tough you might only change a comment somewhere within the source file (as of R2024a-pre).
Is mlock a valid way to prevent this behaviour?
Or is a constant property the better way?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by