In OOP a dependency exists when a class uses the keyword new
to create an instance. Regarding Wikipedia the UML-notation shows a dependency via an arrow that has a dashed line:
The website https://www.dofactory.com/net/command-design-pattern shows code and its UML for the Command pattern. The code on this website has a client-class (I think it's the MainApp
) which contains three times the keyword new
to create an instance for the receiver, command and invoker.
class MainApp
{
static void Main()
{
// Create receiver, command, and invoker
Receiver receiver = new Receiver(); // <- no dashed arrow in UML
Command command = new ConcreteCommand(receiver); // <- dashed arrow in UML
Invoker invoker = new Invoker(); // <- no dashed arrow in UML
// [...]
}
}
Why does the UML only show a dependency of the client to the concrete command
? Because the client also uses the keyword new
on receiver and invoker. I also expect dependency arrows to receiver and invoker in the UML.
Aucun commentaire:
Enregistrer un commentaire