Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What classes must I put in a class diagram? Only classes used in Business Layer and associations between them? Or also other classes in the Data Access Layer, Service Layer, etc.?

share|improve this question
4  
Class diagrams are meant to be a graphical way to describe the relationships between your classes that collectively solve a problem. Do not think you need to make a diagram for all your classes. –  mortalapeman Mar 13 '13 at 17:59

5 Answers 5

Exactly those classes which are necessary to understand the aspect of the system which that particular class diagram depicts.

It could be the entire domain model, or all classes that make up the external API of a particular layer or subsystem, or whatever you think is important.

But note that class diagrams are not the only type of diagram, nor the most useful one.

share|improve this answer
4  
Exactly. Never draw a diagram unless you have a clear idea what the diagram is supposed to communicate -- if something doesn't help communicate that, leave it out. –  Jules Mar 14 '13 at 0:45

You should include all classes in your program, as a class diagram is suppose to describe the entire structure of your program/application.

However, in many applications this process could turn quite complex, so try to isolate the main components (Data Access Layer, Service Layer, Business Layer, etc.) and graph them independently, with proper documentation as to how they interact with each other.

For the class diagram to be useful, you need to divided it by layers, and by components within these layers, if necessary. If it is still too complex, it means you might need to rethink the relationships among your classes. Mapping them all out can help you understand which ones are needed, which ones can be combined, or which deleted, and improve it to the point you have a simpler class diagram, thus a simpler program structure.

share|improve this answer
2  
no, that's not what a class diagram is supposed to do. –  Michael Borgwardt Mar 13 '13 at 18:45
3  
It's supposed to help understand the system. A diagram that includes every single class in the system contains too much data and too little information about which of it is important. –  Michael Borgwardt Mar 13 '13 at 18:58
3  
@MichaelBorgwardt I agree. Which is why I mention OP should try to divide the diagrams into meaningful sections or subsections. But to not include most classes will result in a program diagram rather than a class diagram, don't you think? –  rae1 Mar 13 '13 at 19:04
1  
@MalikaQueen: A good time to stop is when it becomes difficult to read/understand the diagram because it has gotten too big/complex. That's when you start moving sub-components to separate diagrams. –  FrustratedWithFormsDesigner Mar 13 '13 at 21:00
1  
@MalikaQueen Like I mentioned, for the class diagram to be useful, you need to divided by layers, and by components within these layers, if needed. If it is still too complex, it means you might need to rethink the relationships among your classes, and mapping them all out can help understand which ones are needed, which ones can be combined, or deleted, and improve it to the point you have a simpler class diagram, thus a simpler program structure. –  rae1 Mar 13 '13 at 21:08

First of all, you are not limited to one class diagram. You can have as many diagrams as you want! the purpose of the class diagrams is to help you (or someone else) understand the system better, so it is mostly a problem of taste. Some people need to see all of the details to understand the structure of the system and so they need one big class diagram. But other people prefer having the big picture separated into smaller chunks where each one shows only a part of the system, and they can build their own "big picture" in the head.

BTW, you can also create a component diagram that connects the small details of the class diagrams into a more high-level diagram.

share|improve this answer

A class diagram represents an individual component of a system, or the system as a whole. At the highest level you have a System context diagram which shows the individual components of a system.

Class diagrams could represent all classes in a small project however you would be far better placed to have multiple diagrams representing each component in your project.

share|improve this answer

I try to include every class, but sometimes during implementation I may find that a class is rather big, so I split it into small helper classes. I typically don't bother putting them into the class diagram because it would offer little value. They are not design artifacts.

But start off by including everything in your diagram.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.