Book a Demo

Author Topic: Static classes (C#)  (Read 6103 times)

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Static classes (C#)
« on: July 12, 2006, 11:43:59 pm »
I know that class X is going to be static.  It has no methods yet.

1.  How do I tell EA that it's a static class?
2.  How does EA "show" that it's static?

....

99.  How do I get over my phobia of including a class instead of its instance in a sequence diagram?


:(
bruce
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Static classes (C#)
« Reply #1 on: July 13, 2006, 12:03:10 am »
Give it a tagged value of "static" with value "true". If you look at the "Class Definition" code gen template for C# you'll see the condition that causes "static" to be written.
« Last Edit: July 13, 2006, 12:03:43 am by KP »
The Sparx Team
[email protected]

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Static classes (C#)
« Reply #2 on: July 13, 2006, 05:32:29 pm »
OK, that satisfies item 1.

Having now searched the superstructure from end to end, there appears to be no notational aspect applicable to static classes, The only thing I can find is at 7.3.19 that appears to be a cyclic definition ??? which if I stand on my head and look at through the bottom of a large glass of scotch may indicate that a static class name should/could be underlined.  Any thoughts?

I've got over 99. by modelling them as instances anyway.

101.  Is a C# static class something different from an EA static "thing" from a UML static "thing"?

bruce
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Static classes (C#)
« Reply #3 on: July 13, 2006, 07:40:06 pm »
Quote
OK, that satisfies item 1.

Having now searched the superstructure from end to end, there appears to be no notational aspect applicable to static classes, The only thing I can find is at 7.3.19 that appears to be a cyclic definition ??? which if I stand on my head and look at through the bottom of a large glass of scotch may indicate that a static class name should/could be underlined.  Any thoughts?
FWIW, 7.3.19 applies to Features - which ain't Classes.  I strongly suspect that C# Static Classes are like C# Properties; NOT really handled by UML.  See my pontifications elsewhere.  Notwithstanding that, as Neil says, you can get EA to distinguish between a non-static Class and static one.
Quote
I've got over 99. by modelling them as instances anyway.

101.  Is a C# static class something different from an EA static "thing" from a UML static "thing"?

bruce

Given the definition of a C#  Static Class:
Quote
Static classes and class members are used to create data and functions that can be accessed without creating an instance of the class. Static class members can be used to separate data and behavior that is independent of any object identity: the data and functions do not change regardless of what happens to the object. Static classes can be used when there is no data or behavior in the class that depends on object identity.

It would appear a C# Static Class isn't a UML Class at all...  :-)
Quote
A class describes a set of objects that share the same specifications of features, constraints, and semantics.

Since a UML Class implies that there are instances.

That's not to say C# Static Classes aren't very useful.

Quote
The main features of a static class are:
  • They only contain static members.
  • They cannot be instantiated.
  • They are sealed.
  • They cannot contain Instance Constructors.
Creating a static class is therefore much the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated.[/i]


To my mind, its a back door way of saying "There really are non-instance related things that have wide scope" - without having to admit it...

bruce, I think you'll agree they seem to be "Clayton's Classes" - The Class you have when you don't have a Class.

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Static classes (C#)
« Reply #4 on: July 13, 2006, 07:49:15 pm »
Quote
It would appear a C# Static Class isn't a UML Class at all..
&tc

Good!  Now I've got something to hang this on to.

thanks.

bruce

p.s.  I know it was the Feature section, its just Features are/can be classifiers.  Classes are classifiers......   cant I use this stretch of imagination....  :-/

p.p.s.  I've essentially given up and stereotyped the buggers so they stand ouit in the diagram.
« Last Edit: July 13, 2006, 07:59:05 pm by sargasso »
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Static classes (C#)
« Reply #5 on: July 13, 2006, 09:21:28 pm »
Quote
p.s.  I know it was the Feature section, its just Features are/can be classifiers.  Classes are classifiers......   cant I use this stretch of imagination....  :-/
Only 'cos it says Guru on your shingle...    ;)

Technically, you can only apply isStatic when the Classifier is being used as a Feature, not otherwise.  It is not an intrinsic attribute of Classifier.

It's similar to the discussion nearby about Package as Package versus Package as Element.

Paolo

BTW:  What stereotype did you use (and what Notes did you include as definition)?  I'm interested in refactoring some of my classes in this way.
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

mikewhit

  • EA User
  • **
  • Posts: 608
  • Karma: +0/-0
  • Accessing ....
    • View Profile
Re: Static classes (C#)
« Reply #6 on: July 14, 2006, 12:33:57 am »
shingle ... shingle beach - teach ? .... shingle stone - phone ?

Nope, sorry, your rhyming slang is causing me a load of Shania.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Static classes (C#)
« Reply #7 on: July 14, 2006, 01:28:02 am »
Quote
shingle ... shingle beach - teach ? .... shingle stone - phone ?

Nope, sorry, your rhyming slang is causing me a load of Shania.

Informal. A small signboard, as one indicating a professional office: After passing the bar exam, she hung out her shingle.

I was referring to bruce's forum signboard...  (as at left).

Paolo

(Sir Humphrey is turning in his grave...)
« Last Edit: July 14, 2006, 01:28:29 am by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!