Singleton Class

Help
2011-08-07
2013-04-29
  • Mustafa Al Lail

    Mustafa Al Lail - 2011-08-07

    Hello,

    Is there a way to specify a singleton class in USE?

    Thanks,
    Mustafa 

     
  • Lars Hamann

    Lars Hamann - 2011-08-16

    Hi Mustafa,

    because USE does not yet support static attributes or operations it is not possible to specify a singelton class using the original pattern.

    What you can do is to specify an invariant which forces the instance count of a class to one:

    context SingletonClass inv singleton:
      SingletonClass.allInstances()->size() = 1
    

    Note, that this constraint is only enforced if an instance of SingletonClass exists. You have to either put the constraint into the context of some "controller class" or you have to use the USE specific extension existential inv:

    context SingletonClass existential inv singleton:
      SingletonClass.allInstances()->size() = 1
    

    This extension can be translated to "there exisits at least one instance which fullfills the condition" in contrast to "for all instances the condition is fullfilled".

    Regards,
    Lars

     
  • Mustafa Al Lail

    Mustafa Al Lail - 2011-08-16

    Hi Lars,

    Thanks a lot for the detailed answer, I appreciate it.

    Regards,
      Mustafa

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks