"Create" vs "Instantiate" dependency in UML - uml

According to the UML spec we can denote a dependency between two classes by means of <<Create>> or <<Instantiate>> stereotypes.
Do you know what is the differences between those stereotypes?
It is written in UML spec 2.5 (chap. 22.3 Standard Stereotypes):
For <<Create>>
A usage dependency denoting that the client classifier creates
instances of the supplier classifier
For <<Instantiate>>
A usage dependency among classifiers indicating that operations on the
client create instances of the supplier

Michael Jesse Chonoles
Yes, «create» is used on sequence diagrams. It's a stereotype on a message. «Create» is also a stereotype on a behavioral feature in a classifier indicating that is a constructor of instances of that classifier (or the equivalent for non-object-oriented items).
When «Create» is used on a dependency, it doesn't seem much different than «Instantiate». Personally, I use the dependency «Instantiate».when I mean a true object-oriented instantiation arrived at by calling the constructor (which is how the I would translate the model into code). I would use «Create» when it's a different kind of creation, either more indirect, conceptual, or non-object-oriented features.
Here are some examples. I would use «Create» to say MSWord-->«Create» a Document, a modeler «Create» a model. Though I normally wouldn't model this in detail, I would use «Create» to indicate a component «Create» a new database record, the database manager «Create» a new database, a programmer «Create» a new app. Or create a new element in a (non-oo) array. These can happen without directly calling a traditional object-oriented constructor -- and can't be directly converted to code.
On the other hand, if I had a marriage operation on a person, it would probably «Instantiate» the association class object of marriage.
Because most of my modeling is conceptual, in practise, I tend to use «create». Though, even then it doesn't come up that often.

I noticed that << Create >> stereotype can also be applied not only to "Usage" dependency but also to
"BehavioralFeature" (see section 22.2 in UML spec).
In UML "BehavioralFeature" corresponds to particular methods in a class or interface.
Hence if we mark particular method in a class with << Create >> or << Destroy >>
we mean that it creates/destroys an instances of this class.
We can make a parallel between marking a method with << Create >>
and marking a Usage Dependency with << Create >>.
If we mark a Usage Dependency with << Create >> then
this means that particular method in a Client Class creates an instance of a Supplier Class.
Hence we create an instance of Supplier in the body of our client class.
Client and Supplier are strongly coupled here.
On the other hand if we mark a Usage Dependency with << Instantiate >> then
Client class delegates the creation of Supplier to the other Objects.
Hence, he creates Supplier indirectly.
In this case Client and Supplier are loosly coupled.
For example, this happens if we create Supplier via one of the Creational Patterns: Object Pool, Prototype, Factory Method etc.
Note:
By and large, it is not very clear the differences from the spec.
Hope in future releases of it (more than 2.5 version) we have more clear definitions.

The person who instructs me on SyML/UML has done MSBE in SyML/UML for very many years in large very companies.
I asked him how to draw a diagram that shows:
The 'system Boot process' loads (from ROM) and runs the 'system MAIN process/application'.
He said I should use the «Create» usage dependency.
So as I see it:
You use «Create» to show that one process runs 'big' things - like
booting up an entire external process / SW item / application.
You use «Instantiate» to show that within a given process, a code
segment instantiates "creates" an object instance from a class
definition.

Related

Aggregation vs Composition

I am wondering is the relationship between a Human and a Driver License an aggregation or a composition? It's clear for me that a Room and a Building relationship is a composition and a Chair and a Room is an aggregation. But a Driver License can exist without a Human but it makes no sense of its existence without a Human. I got stuck.
Since a driver license is not part of a human/person, but just related to her/him, there is neither a Composition nor an Aggregation between them, but just a plain Association.
The answer of Gholamali-Irani confuses the fact that a driver license must be associated with a person (that is, the resp. association end has an EXACTLY ONE multiplicty) with the (contingent) characteristics of many compositions to have inseparable parts, and mistakenly concludes that the Association must be a Composition.
In many cases, where we may wonder if an association is a composition, it is safer to model it as a plain association.
The only good reason for modeling an association (like Human-has-DriverLicense) as a composition is when the instances of the component type (here the driver licenses) are "weak entities" not having their own identity. But driver licenses do have their own ID, so there is no need, and no gain, to model them as components of their bearer.
I think that to answer the doubt in this question, we should define the following terms exactly:
the Context
Existing of an Instance in the Context
If the above terms are defined exactly, then there is not any doubt in using a Composition or an Aggregation.
I my idea, if I want to ask this question, in the my specific definition of terms:
Context : Real World
Existing of an Instance and destroying it: the usefulness of Instance is not related to it's Existence. Destroying it means to invalidating it. We should invalidate it after vanishing the owner. (But we do not do it immediately)
So, the relationship between a Human and a Driver License can not be a composition in the real world context. Because, by destroying a Human (vanishing, lose the life ,...), we do not destroy the Driver License immediately. It exists.
For example (in some countries), there is not any online and up-to-date invalidation mechanisms to invalidate a Driver License immediately, so it can be exist without the Driver until we invalidate it. So in this period of time (from vanishing the Driver to invalidating the Driver License) it exists and the usefulness of Instance is not related to it's Existence. Note that again: it is my definition of Context and Existence.
Edit (Based on #Thomas Kilian's comment):
For another example in the Context of Programming and it's technologies (like ORM), we should delete (invalidate) the Driver License immediately after deleting a instance of Driver (and we can do it in this Context). So the relationship should be a Composition.
Finally: I want to point the importance of the definition of terms (Context and Existing and other related terms) in modeling. If we do not define them exactly, many solutions appear to the problems (based on hidden definitions in their minds).
Hope to help.
Aggregation implies a relationship where the child can exist independently of the parent. Example: Class (parent) and Student (child). Delete the Class and the Students still exist.
Aggregation Example:
It's important to note that the aggregation link doesn't state in any way that Class A owns Class B nor that there's a parent-child relationship (when parent deleted all its child's are being deleted as a result) between the two. Actually, quite the opposite! The aggregation link is usually used to stress the point that Class A instance is not the exclusive container of Class B instance, as in fact the same Class B instance has another container/s.
Composition Example:
We should be more specific and use the composition link in cases where in addition to the part-of relationship between Class A and Class B - there's a strong lifecycle dependency between the two, meaning that when Class A is deleted then Class B is also deleted as a result
Composition implies a relationship where the child cannot exist independent of the parent. Example: House (parent) and Room (child). Rooms don't exist separate to a House.
Here is some additional information to elaborate the concept of Composition
As what Grady Booch Stated in the UML User's Guide, Addison Wesley
However, there is a variation of simple aggregation - composition - that does add some important semantics. Composition is a form of aggregation, with strong ownership and coincident lifetime as part of the whole. Parts with non-fixed multiplicity may be created after the composite itself, but once created they live and die with it. Such parts can also be explicitly removed before the death of the composite.
In addition, in a composite aggregation, the whole is responsible for the disposition of its parts, which means that the composite must manage the creation and destruction of its parts. For example, when you create a Frame in a windowing system, you must attach it to an enclosing Window. Similarly, when you destroy the Window, the Window object must in turn destroy its Frame parts.
(Source: UML User's Guide - by Grady Booch, James Rumbaugh, Ivar Jacobson, Addison Wesley)
Summing it up - (Read detailed Article)
To sum it up association is a very generic term used to represent when on class used the functionalities provided by another class. We say it's a composition if one parent class object owns another child class object and that child class object cannot meaningfully exist without the parent class object. If it can then it is called Aggregation.

Non-UML diagrams to show objects and their creation

I am trying to understand new piece of project. I am drawing UML class diagrams, but there is something missing for me in these diagrams: the creation of objects. What a traditional UML diagram can depict is how these classes are related to each other and how instances of these classes are related to other objects of other classes, but that is in the moment when they are already created. Sometimes it is not that obvious who creates who, sometimes it is totally misleading. For example objects of class A may create object of class B, but that A object just returns this B object and gives it to somebody else and doesn't hold any reference to it. And sometimes it holds (a reference or pointer). Sometimes it matters for the reader. So in fact there are two types (pieces) of information: holding and creating. I came up with my own way of visualizing this, but maybe there is something standard here? What do you think? And I don't have UML Object diagram in mind, that is not something very helpful when reading C++ or Java code and trying to understand the relation of classes and objects. And not sequence diagram also, that's a different kind of beast.
If you want to stick to class diagrams, you can use the «create» usage dependency from UML Standard Profile (chapter 22 of UML 2.5 specs).
«Create» | Usage | A usage dependency denoting that the client classifier creates instances
of the supplier classifier.
So e.g. here A creates an instance of B, and C just has a reference to B.
A type of UML diagrams show only one particular view of your system by abstracting the other aspects of a system. For example, a class diagram shows only the static aspect of the system, but not the dynamic behavior such as:
At what time an object was created
The central ideas of modeling a system is trying to deal with (or focus on) an aspect at a time, and at the same time to eliminate the complexity by forget about the other aspects of a system.
In this case, "creating an object at a particular time by who (another object)" should be dealt with behavior view, thus, we can use a sequence diagram to modeling the dynamic behavior:
You can see the Dimension of a sequence diagram in the Figure:
Horzontally, Objects Lifecycle
Vertically, Time
You might then be interested, how I can relate these models together? Will there be any inconsistencies among them? Right! if you are puzzling about this, you are in the right track!
Look! models are inter-connected each other, take an example, you can create a use case, and a use case can be detailed with a number of scenarios, then.. each scenario can be modeled by a sequence diagram, and the sequence diagram giving you the hints of what objects (and what operations and attributes in it) you need to build your systems, right?

UML meta-modeling

I have read about meta-modeling (including M0,M1,M2,M3)
I understood the goal of M0 (runtime execution), but I don't understand the meaning of M1,M2, can someone give a good example to where and how to define a profile? and what is the meaning of the tagged values in a profile?
They are abstraction levels. The higher the number the more abstract the definition. The M3 level describes a framework in which you build your system. This framework is called profile. Imagine a car factory. They build cars. So in the profile you define such a car with what it would need. Then you can create a car class in a concrete model and it is distinct in certain respects (e.g. it must have 4 wheels, a motor etc.). Or take requirements: A requirement can simply be a piece of text. But in your modeling environment you might require them to have a distinction functional/non-functional, a source, a priority, whatever. So you define those as attributes in the meta-model and when you use the so defined Requirement stereotype the concrete class will have tagged values with the name of the attributes.

Sequence Diagram - Lifeline modelled as Class or System

is it allowed to draw a sequence diagram with classes and systems as lifelines.
For example:
I want to model a part of the domain logic with a sequence diagram. Can I model a the lifeline once as a class and once as a whole system (remote system or a whole layer/jar file)?
Example-1:
There is the Class Scheduler which invokes the FileDownloader class which calls a FileServer? So I have the "Scheduler" (Class) the "FileDownloader" (Class) and the "FileServer"(remote System) as a lifeline.
Example-2:
Or I have a Class called Scheduler which invokes the "AccountingService" which calls the "Persistence Layer" which calls the "Database"
So I have the "Scheduler" (Class) the "AccountingService"(Class) the "PersistenceyLayer" (Whole Layer or .jar File) and the "Database" (System).
Is it allowed to mix these up in a sequence diagram. In some descriptions about sequence diagrams there would only modelled classes that call classes or systems that call systems.
Thanks.
What do you mean by "System" ? In UML there is not definition of system. You probably mean System as a name of Class or Component, or is it a stereotype? If yes, you can mix it.
Jar file is artifact. Artifact is Classifier as well. If artifact plays role in internal or communication structure, it can be represented by lifeline as well.
Lifeline represents instance of specific type which participate in interaction. Referenced type could be any connectable element from classifier owning interaction (sequence diagram, for example Class, Component or other types of classifiers).
To learn more about UML, I recommend you to read UML superstructure specification document.
Dowload it for free from omg.. UML Superstructure
Lifeline usually represents a role (it can be what you call system or even a human being), or an object. Notice, not class but its instance! Lifeline represents any thing with some behaviour. Classes mostly describe not their own behaviour, but behaviour of their instances. You'll have a class as a timeline only when you are modelling its static fields and functions. Or when you are in JS or similar language and your class is really a prototype
So, mixing of large and small objects, components or roles is absolutely OK. It is a part of standard UML usage. But do not mix instances and classes if you are modelling for "traditional" languages! Are you sure that it is the class "Sheduler" that invokes something, and not an instance myBestSheduler of this class?
In sequence diagrams, displaying a class means "when I make an instance / object of this class, this activities occur".
And, other external stuff, that interact with your program, like the users ("actors"), Shared Libraries /DLLs, Web Services, Operating System, Network, whatever ...
... are considered objects ("instance of a class").
A Sequence Diagram, is composed by several objects, each one, with its own "Lifeline" or "TimeLine", that interact among them, (several "Lifeline (s)").

Use fields specified in a CU into another CU

I have a CU that extends another CU, let's say: Add inventory extends Add product, so in one product interface I need to use fields from inventory CU, how I can described this in a CU?
"Extends" means that during the "execution" of the extended UC, execution of the extending UC has been voluntarily invoked by an actor. Each UC is described by several scenarios. Scenario is decribed as an ordered sequence of "steps".
You have to specify so called extension points - steps in the scenario(s) of the extended use case, in which the Actor can invoke the extending UC's execution. It can be a single step or a range...
You can think of the extension point as of a method with parameters, tmplemented in the extending UC and invoked by the extended UC. These parameters could be these fields, you need to "pass" to another interface.
In my projects I always "back up" the my case model with the domain model (class diagram) and use elements of it in the specification of the UCs (preconditions, postconditions, scenarios, extension points).
UPDATE (after the comment)
UML does not define the concrete format of the use case specification, it only defines the concepts and their semantic meaning. A UC can have so called Behavior, can extend another one (or be extended), has Extension points.
The way you define Behavior and Extension points are your own choice.
So, in my example:
Behavior of both UC is defined as a textual sequence of steps, as performed by System or User (alternative is a state machine, activity diagram, even user interface prototype)
Extension Point is defined as a step in the sequence and additionally described by this "method" signature, to illustrate the exchanged information
Remember that UCs show INTERACTIONS beetween the System and the outside world. For them is the System kind of black box. Conceptual model I've used here is therefore NOT a DB or system design, but rather a conceptual, implementation-agnostic view on the entities used by the app. They can even be mapped on 2 different systems on the implementation level!
Relationships between the UCs similarly exist purely on the user-system interaction level of abstraction, and DO NOT BY ANY MEANS reflect some internal system dependencies!
(note added after Gangnus's comment)
(Scenarios and concepts are fully invented for the example sake)
UML standard 2.5, p.680, definition:
An Extend is a relationship from an extending UseCase (the extension)
to an extended UseCase (the extendedCase) that specifies how and when
the behavior defined in the extending UseCase can be inserted into the
behavior defined in the extended UseCase. The extension takes place at
one or more specific extension points defined in the extended UseCase.
Extend is intended to be used when there is some additional behavior
that should be added, possibly conditionally, to the behavior defined
in a UseCase.
I wouldn't call what you are describing an extension. Inventory instance is a container that has Product instances as items. So, Add Inventory is a behaviour that depends on existent products, but not on ways of their adding. So, if you use correct OOP strategy, Add Inventory is absolutely independent on Add Product behaviour. They are both independent behaviours.
Yes, they work on structures, that are dependent and associated, but structures mostly are described in other diagrams. So, normally, these two behaviours are two different independent UCs.
On the other hand, according to standard, you can mix elements of different diagrams, and if you MUST show that intermediate dependency on UC diagram, you can draw there appropriate classes(Product and Inventory), connected by an association. Your use cases will be connected to these classes by arrow "dependency" - - - - - - >
Notice, that Use Case "add Product" and method "addProduct" in some class are absolutely different things. The first is behaviour, described in manual, with participation of user, and the second is a piece of code. The first is the task and the test for the second - that is a realization. So, beware, put classes into Use Cases only if you understand what you are doing VERY WELL, it is not the way for starters. Minimally, reread the Use Cases chapter of the UML standard before. Personally, I would show classes in separate classes diagram here. It is much more easy way.

Resources