Question

Let's say I have a Customer class and a Product class. A Customer can search for Products, possibly filtering results. Can I model this as an association between Customer and Products, entitled Searches using an association class, like for example Filters?

+---+   SEARCHES >  +---+
| C |-------+-------| P |
+---+       |       +---+

            |

            |
          +-+-+
          | F |
          +---+

If this is valid, then is this a good idea?

Was it helpful?

Solution

No, you have mixed use case with class diagram here.

A class diagram

  • The fact that a User Searches for a Product, is a Use Case. Realizing it in the class diagram, you needn't really to have these three classes so close together. But you can, of course.
  • In Class diagram you should show the structure of the system, not its behaviour. So, this "SEARCHES>" note shouldn't be here. Not only because it is out of scope of Class diagram. It is worse. Class Customer IS NOT an actor "Customer", it is not human by itself, it is merely a record about him in the system. And this record does not conduct any searches.
  • You can show a search on the class diagram, making Search a class or a function. I would name it a class, so you could have an instance of this class for every search ever done.
  • Of course, you can use a class Filter, as well. With elaborated functions that could get a Product list according to the filter.
  • And of course, the more important part about the Customer will be the history of his buys, not his searches. So, I added it. And it is only the start - you need to support the processes of buying, payment, delivering, logging and so on.

enter image description here

A use case diagram

Here you need only show an actor Customer and a use case: Search. And connect them. No Product or Filter here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top