views:

372

answers:

5

In Uml sequence diagram, shall we include private functions of a class?

+5  A: 

No. You want to be able to change internal (private) operations without affecting anything on the outside.

If you refactor your internal operations then everything that relies on the public API should be unaffected. I'd include documentation in this.

EDIT: more explanation as requested

You want client classes to depend on the public API of your class. Therefore you should only document the public elements of your class. You want the freedom to change the internal (private) operation whenever you need to, without affecting any dependent entities.

dave
will you please explore it more..
Jaswant Agarwal
+1 for encapsulation.
Rap
+2  A: 

Sequence diagram is one of the interaction diagrams, so, IMHO, you should avoid including private functions.

http://en.wikipedia.org/wiki/Sequence%5Fdiagram

Gacek
+1  A: 

In general yes, hiding privates is what you want to do since UML is designed to show the public API of a given system/module. Though it also depends on the purpose of the UML, if the UML is for your own use and you want to see those privates when you look at the diagram, then yeah, put it there. I've printed out some UML of my code with privates so I could see them, but that was for me and not intended as documentation for other users.

dharga
+2  A: 

(The following answer assumes you are not trying to go for an executable model -- that is, one that generates code from UML -- but are using models to help spec work that will be done by people.)

All models are "wrong", but usefully so. Model are, by definition, incomplete descriptions of what you are trying to build -- think blueprint for a house vs. a finished house. With this kind of modeling, models should only show the key aspects of the system you are trying to build.

What constitutes a key aspect? The answer is, whatever the team needs to know in order to build the real thing. In a house blueprint, the electrician just needs to know where the outlets will be placed, and a few key details about load and interconnects. He doesn't need a model of wiring up an outlet; that, he knows.

So, if your team needs to know about private operations, then go right ahead and model them. In the sequence diagram, you show a self-call by sending a message from the class lifeline back to itself.

However, if private operations are unimportant, feel free to leave them off the sequence diagram as extraneous detail. I would recommend, however, that you document all operations at least at the class element level in your model. Even if you just give the operation a name, you've documented the fact that you'll need to have it filled in at some point.

+1  A: 

Showing the private methods in Uml sequence diagram will not be feasible .. i think we should show only public methods to it..