[Uml-devel] kdesdk/umbrello/umbrello
Andrew Sutton
ansutton at kent.edu
Mon Feb 24 14:51:06 UTC 2003
On Monday 24 February 2003 4:48 pm, Mathias Meyer wrote:
> That point is clear I think.
okay
> > on a related note - if anybody's going to do any work for this - here's
> > how templates in UML are supposed to work. something (lets call it
> > UMLClass in this case) has a list of template parameters. if that list
> > is NOT empty, then the UMLClass becomes a "template". i.e., it cannot
> > be used like a regular class (can't be used in inheritance or as types
> > of other objects like attributes or parameters). you have to define a
> > special object called a "binding" (or UMLBinding) that contains values
> > for the template parameters of the template class. this new object (the
> > UMLBinding) can then be used like a regular class. does that makes
> > sense?
>
> I'm not sure, if I get what you mean, but I think so. I'll have to think
> about that again. Does UML explicitly forbid inheritance of template
> classes, since you can do that in C++ afaik? Obviously not for normal
> classes, but for new templates. That's what Stroustrup does in his book.
> Please correct me, if I'm wrong here. Maybe I'm a bit confused by mixing
> UML and C++ features ;)
it's not really all that clear a subject :) i should define the problem a
little better - the issue is with parameters and arguments.
a parameter is the specification of "something"
an argument is an instance of that parameter
consider the following...
void foo(int a) { ... }
void bar() { foo(3); }
here, "int a" specifies the parameters to the function foo. in the function
bar, we call foo with the value "3". "3" is an argument - an instance of
"int". we can do the same with classes:
template<typename Type> class List { /*... */ };
typedef List<String> StringList;
in the above, the parameters to the class is "typename Type". The argument
corresponding to the template is "String".
in C++, when you provide arguments to the template, the compiler [should]
automatically instantiates the template (the equivilant of creating a UML
binding). at the same time you can't use the template class without
arguments.
class SomeList : public List { }; <-- error
class AnotherList : public List<String> <-- fine
UML follows the same rules. if there are parameters to a class (or any
object), it becomes a type factory. Any binding to the template parameters
will instantiate a new class. However, in UML, we don't have the benefit of
implicit template instantiation.
does that help at all?
andy
More information about the umbrello-devel
mailing list