Re: global variables in UML class diagrams (novice question)



Responding to Amadej...

I hope I'm not totally out of context if I ask some novice questions
about UML class diagrams. I'm trying to learn how to model with UML
and I think I've got all the basics down, apart from what to do with
global variables (that's basically my main concern right now). Coming
from a MFC and C++ background, global variables (outside the class
scope) are something that I'm dealing with frequently. One good
example would be a derived class from CWinApp from which the majority
of my applications start. I often store variables in that class so
that I can access them later on from any other part of the application
since each application generated by the MFC wizzard has a static
instance of that class that is globally accessed.

The short answer is: there are no global variables in OO applications.

Knowledge attributes are defined with objects that logically know something in the problem space. Access to those attributes is then restricted by defining and instantiating relationships between objects. Thus when one has

1 R1 is related to *
[A] ------------------------- [B]
+ attr1

When the relationship is instantiated for a particular A, that A will only be able to reach B::attr1 for the set of [B] instances that are defined in the relationship instantiation. Those will typically be different instances of [B] than those related to a different instance of [A].

While not illegal, reviewers will want a very good justification for an object whose attributes are accessible from all objects of another class, much less all objects of all classes. IOW, that all-inclusive relationship had better exist that way in the problem space.

BTW, that's why the Singleton pattern is highly overused in OO applications; often it is just a kludge to introduce global data, which is a no-no.


*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl@xxxxxxxxxxxxxxxxx
Pathfinder Solutions
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
"Model-Based Translation: The Next Step in Agile Development". Email
info@xxxxxxxxxxxxxxxxx for your copy.
Pathfinder is hiring: http://www.pathfindermda.com/about_us/careers_pos3.php.
(888)OOA-PATH



.



Relevant Pages

  • Re: Application logic and Business logic
    ... >>But memory without structure is gibberish, ... the idea of sharing data between applications is ... your account's balance in their reports. ... they are volatile global variables! ...
    (comp.object)
  • Re: Global Variables
    ... You should avoid using global variables like you would avoid a virulent ... Global variables will not be available to other applications either. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Application logic and Business logic
    ... Data without application is memory. ... the idea of sharing data between applications is ... they are volatile global variables! ... > swapped brains, neither could both applications run on the same brain. ...
    (comp.object)
  • Re: Understanding Modules ?
    ... containers for functions and Global variables - in what circumstances do ... Can you put multiple functions in one ... Because your applications might have many different features and functions, ... I placed my re-link code in a ...
    (microsoft.public.access.gettingstarted)
  • Re: Global variables
    ... >> Do you tend to rely on global variables, or do you shun them completely, ... > holding some state variables that is reachable via some relationship ... > solution" is dictated by the problem space rather than being a developer ... > Without Singletons, the actual instances one can reach via relationship ...
    (comp.object)