When should I use generalization in case of use?

  • what is generalization for in the use case?
  • when do I owe the generalization?
  • If I own 2 actors, one student and the other teacher, they are respectively users, then would I enter the generalization part?

Source: Wikipedia

Author: Maniero, 2019-10-02

2 answers

There is some controversy about this. There is a "school" that thinks in a way and it is the most academic possible, in fact it is the one used in virtually every example of book, blog, course or other way that sees out there how to do generalization. And there is the pragmatic "school" that tries to think about how things really are and so can give a greater chance of not having problems in the future. Even these people understand that inheritance, and carrying the generalization is almost an anti pattern nowadays and that some people already realize that if you have to generalize it should be with an abstract class or interface (or trait where this exists), that is, a concrete class cannot be generalization.

Then your example follows the academic "school" (no pun intended with the domain of the example). She believes that the same real object can exist in multiple instances of the system, either in the same line of specialization, or in the most general, and even more so, it can exist on different lines, so it uses an inheritance from one concrete object to another object. My experience and already corroborated with many people I know who are not followers of cake recipe who believe that what is in the books serves for something real is that this does not exist and causes problems in modeling.

Who is pragmatic knows that student, teacher and user are distinct things, and in general are roles that people exercise in the system (or organization). A person is composed, among other things, by their roles, or else a role is composed, among other things, by a person. In composition there is no generalization. Eventually a role could be a generalization of these specific roles, but I don't usually see it that way because I don't see what a role has in common with each other, but it's something possible. If generalization is done in some specific fact it can be through interfaces. Giving a general ability to an actor is something that happens more than more general generalization.

So the use case needs to consider what that object can do and if you have other objects that do exactly the same thing, even if with specific ones, there is some form of generalization, but completely, only in this specific feature. So student and teacher can have something that they do in common equally and this allows a partial generalization, but they are not specifics of an actor but of an action.

A generalization that I always see is a person being a generalization of natural person and legal person, where the first would be abstract and the other concrete, keeping that idea that the most general object can not be concrete.

In the academic "school" it is enough to have something in common that should already make the generalization. This group of people thinks that, at least in some cases, if you have a name on two objects can already generalize because it has something in common, even if that name nothing have to do with the other name. They ignore the Liskov principle .

What I see is that it takes a lot of experience to know how to generalize, and therefore program object-oriented, because it is not easy to see when it should do or not without knowing what gives problem. It takes a lot of experience with taxonomy and even ontology and who knows dialectics. You can study these things, but only experience gives you good conditions to deal with it. More and more I believe that OOP it should only be introduced to programmers after a certain time, who knows when it is making the transition from junior to full and the exercise of this discipline really happen only when the person is Senior (really, not only that has the title), who do not make these mistakes of academicism so easily.

One thing I talk about a lot is that you need to be very clear about what you're doing. I will give an example: you put the word respectively, but have nothing respective ali, then even though unconsciously is already seeing the problem in a way he is not. Of course you can review this, but if no one more experienced talk will probably make some mistake in modeling with this. So some have difficulty evolving to learn, they do not want to hear who is more experienced, who can give a parameter and show where she is wrong. Of course, the person should not blindly trust everything that they say to him too, because everyone can make mistakes, they have to creating your own consciousness, it takes time.

So then you first have to choose which "school" you will follow. Pragmatics makes learning faster, but it is not well seen in certain circles that it still buys the idea of academia and tends to classify as wrong if it does not follow what is in the books.

 2
Author: Maniero, 2019-10-02 12:01:33

Generalization in use cases is analogous to generalization in database or object orientation (which we call inheritance).

When talking about actors, multiple actors can play the same role in a specific use case. Generalization is how one represents this, one actor can "inherit" characteristics from another.

If I own 2 actors, one student and the other teacher, they are respectively users, then I would enter the part of the generalization?

Not necessarily. This will depend on the rules of the application. For all intents and purposes, all the primary actors will be users of the system (who will interact through some kind of graphical interface). Generalization has the most with sharing characteristics.

Think of actors as being specific roles that access certain actions and a system user can play different roles.

To illustrate what I mean, here go a small example. Imagine that we are creating the use case diagram for a library in a school and we have the following rules:

  • students and teachers can book books
  • students and teachers can search the book catalog
  • teachers can request new books

Note that, whatever students can do, teachers can too. That way, we could use generalization and make the actor teacher inherits the characteristics of student.

Use case diagram example using actor generalization

 2
Author: LINQ, 2019-10-02 11:55:04