There are people who deny the climate change… I’m not one of them. It is hot here today.. and my Home Office does not have an Aircon… Well… just ignore the heat and keep on writing! Today an item about Class Variables in ‘C’.
I got a question in email@example.com (An email address normally only for customers with a valid support contract. But we will do our best to answer all questions from all people)
The question was: Does Rhapsody in ‘C’ has a possibility to use Class variables, i.e Attributes that are shared over all instances?
The answer is, yes with some little tricks!
Class variables are actually not difficult. Normally, Attributes are generated inside the Class structure and can never be declared static, that is a disadvantage of ,C‘.
But we also have types that we can use. A Type will be generated outside the Class structure. In combination with a <> „New Term“ we can, with a minimal amount of hand labour, create a Class Variable that helps us in creating a real Singleton.
The stereotype does the following:
– It sets the name for the variable (prefixed with the class name) and the visibility. – The variable is declared „static“ so it is not visible outside the C file.
– Visibility is set to private.
TheType must be „LanguageType“ and the declaration must be the desiredType. %s is the name of theType.
The nice thing about this is that it really looks good in your browser tree, very logical what is happening, as it should be!
Happy Modeling with Rhapsody!
Walter van der Heiden firstname.lastname@example.org