Re: global variables in UML class diagrams (novice question)
- From: "H. S. Lahman" <h.lahman@xxxxxxxxxxx>
- Date: Sat, 29 Sep 2007 21:28:29 GMT
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
.
- References:
- Prev by Date: Re: Concrete classes in class diagrams
- Previous by thread: global variables in UML class diagrams (novice question)
- Index(es):
Relevant Pages
|