What is the differences between the Class
and Actor
in UML. Can I use an actor in use case diagram which is used as a class in a class diagram?

- 559
- 4
- 15
-
1There is no relationship between them at all. Use Case diagrams depict a user's interaction with a system (i.e. capturing scenarios which depict how they would use that system). Class diagrams are for depicting the structure of a program's source code. – Ben Cottrell Feb 23 '20 at 14:16
-
@Ben _"Use Case diagrams depict a user's interaction with a system"_ That's not necessarily a _human_ user. An actor could be considered any component that interacts with a system from outside of it. – πάντα ῥεῖ Feb 23 '20 at 14:23
-
@πάνταῥεῖ Indeed, a "user" doesn't necessarily mean a human. – Ben Cottrell Feb 23 '20 at 14:28
-
`actor` is a type of components in `use case diagram` whereas, `class` is itself related to a type of diagram, `class diagram`. What makes you interested to compare between two different prototypes? – Sazzad Hissain Khan Feb 23 '20 at 15:17
2 Answers
I want to know,what is the difference between the Class and Actor in UML
Off hand definitions are:
- A class is a blueprint for objects. With objects being encapsulations of data and behavior. Alright, not always true, as there are static classes.
- An actor is a user that interacts with yours system. Hmm… replace “user” with external entity. Sometimes the external entity is not a user, but it is used. Usually, not always, an actor represents a role of users.
UML definitions are a more involved, I’m trying to condense them here:
First, we need to say that there are classifiers. The classifier is both a type (as in data type) and a namespace. It contains "things" that are interrelated.
Next a class is a classifier, that contains attributes (state) and operations (behavior). It is also worth noting that there are instances of classes, which we call objects.
Finally Actor are also a kind of classifier. However, they are external to the system. As such we define nothing inside them. The actor will be involved in use cases, which model the interaction with them. Use cases are initiated by actors.
Please note that the UML standard goes into a lot of technicality. For regular use, all that technicality is not necessary, it is rarely useful, and can be detrimental. In fact, you should be more interested in the technicalities of the programming languages you will be using.
I also want to know that do I use a actor in use case diagram
What have you been using?
Perhaps the root of the confusion is that there is actor inheritance. When an actor inherits from another, it means that everything that is true for the base actor is also true for the derived one. Which is useful to model roles.
It is also worth noting that an actor does not have to be a human. It can be any external entity. Which, yes, it would include a class in another system.
Another possible source of confusion is the representation. You may know that stereotypes can be added as tags in guillemets (a.k.a. angle quotes, a.k.a. sideways double chevrons). However, stereotypes can also define an icon. Then you can use the icon to represent the element to which the stereotype is applied.
For example, we can define a stereotype for database actors that has as icon the traditional cylinder database representation. Then you can represent those actors with that cylinder icon. This is how you extend UML.
As it turns out, UML pre-defines some stereotypes. Including those circles for interfaces that look like antennae. Yes, the stick figure for actors is a stereotype.
Now, all classifiers can be represented as a rectangle. You can use the rectangle with the icon of the stereotype in the corner, or you can put the stereotype as a tag in guillemets. Because of this, it is valid to represent an actor with a rectangle with a name (just like a class or any other entity) with the «Actor» stereotype tagged.
Please do not do that. The only excuse would be a limitation of the tools. Then I will condemn your selection of tool.
which are used class in class diagram
I'm not sure I parse. So I will cover my bases...
Yes, you use classes in a class diagram. And you use actors in a use case diagram.
It is ill advised to mix them. Why? Classes are structure. Use cases are behavior.
If you put a class in a use case diagram, I will understand that it is some component with which the system is interacting. That is, I will assume it is an actor. If you put an actor in a class diagram, I will go "wtf!", and then I will ask if you mean one of those gateway classes that Robert C. Martin uses (that is a class whose responsibility is to implement a use case).
It could be that what you really want is to bridge from a use case diagram to some class diagrams. Sure, you have use cases, but what classes are involved there?
Well, if this is what you need, you can make documents where you specify the use cases. If you want to do with the help of UML, I will point you to sequence diagrams, activity diagrams, and interaction diagrams.

- 8,921
- 2
- 25
- 35
As answered here by Bart van Ingen Schenau,
In UML, an Actor is always something (a system or person) that is outside the scope of the system/software that you are building. It would be completely wrong to equate an actor with an instance/object of a class that happens to model certain aspects of the actor in your system.
In the shown UML diagrams, the actor "User" (with it's stick-figure icon) represents the real-world human being that operates your system. The class User represents a model of that person that captures the characteristics that are relevant for you. This class only exists within your system. This makes that the class and the actor are two distinct entities and should also be shown as such in your diagrams.
Although not directly related to your post, this might help you.

- 559
- 4
- 15