Re: Is this correct?!!!



Responding to Mojtaba_danai...

Is the following correct?

Dependency
UML

Bart------>Fooo

Implementation in C++
class Foo { ... };
class Bar
{
public:
void doSomething(void);
};

void Bar::doSomething(void)
{
Foo foo;
Foo * foo1 = new Foo;
// ...
delete foo1;
}

Does the above implementation correspond to UML (dependecy). If not,
what is correct UML for the code?

No. A dependency would exist if a change to Foo affected Bar. An example would be

void Bar::doSomething (Foo* foo)
{
int x;

x = foo->doIt();
this.attr1 = 5 * x;
}

Now if you change the definition of what Foo::doIt does, you change the returned value of x. That, in turn affects the results of invoking Bar::doSomething (i.e., the value stored in Bar::attr1 is different).

A somewhat looser view of dependency applies to physical coupling. That is, if the definition of Foo changes -- represented by a change to Foo's header file, then Bar needs to be at least recompiled even if Bar does not directly access the affected portion of Foo's definition. That's because in languages like C++ the mapping of address offsets can be affected in curious ways behind the scenes. So dependency in this view comes down to what Bar needs to know about Foo. IOW, Bar is dependent on Foo if Foo's header file is in Bar's includes.

However, this loose view really isn't very practical. One is probably better off using a "hard" view like my example where the dependence is behavioral (i.e., on the specification of Foo's behavior). But then it is usually pretty easy to eliminate such dependencies by redefining collaborations, in which case one doesn't need to define them.

FWIW, I don't think one should worry about dependencies in UML. They are really mostly a concern for OOPL code maintainability, which is more properly an issue for OOP.


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

H. S. Lahman
hsl@xxxxxxxxxxxxxxxxx
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
Pathfinder is hiring: http://www.pathfindermda.com/about_us/careers_pos3.php.
(888)OOA-PATH



.



Relevant Pages

  • Re: linking C++ functions in a C program
    ... contains one function named foo() which is compiled in C, ... Therefore, no matter how you classify bar(), this program ... void foo; ... guess the compiler can generate two references to foo, one adorned, ...
    (comp.lang.c)
  • Circular dependency - I think..
    ... The header file for FOO is composed of BAR, ... int GetFbk(); ... void ComputeTorquerCmd(); ...
    (comp.lang.cpp)
  • Re: is assignment atomic/thread safe?
    ... void foo() ... with one thread running foo() while another runs bar(). ... and thus no guarantees are made about _when_ any given piece of code will execute. ...
    (comp.lang.java.programmer)
  • Re: Library bug or my fault?
    ... compiled using ARM/Linux cross-compiler and run on an ARM9 target. ... void memcpy ... 29 void cp(const Foo *foo) ... 31 Bar bar; ...
    (comp.lang.c)
  • Re: Insert with response
    ... FooBar, there's no way and no need to put them in synch. ... column in the foo table to 250 calumns in the bar table. ... set statistics time off ...
    (microsoft.public.sqlserver.programming)