views:

138

answers:

2

I have introduced the SOLID principles to my team and they understand and are excited about using the principles.

S - SRP - Single Responsibility Principle
O - OCP - Open/Closed Principle
L - LSP - Liskov Substitution Principle
I - ISP - Interface Segregation Principle
D - DIP - Dependency Inversion Principle

I have given them a couple of projects that have already been re-factored to use these principles. The biggest problem that I see if they have a hard time seeing the connections between the very loosely coupled classes within the project. Even if I create a class diagram it won't show any connections. One particular project I am referring too uses Dependency Injection and XML configuration for the implementations. While, this has it's purpose it makes it even harder for them to find out what class is even being used.

What is the best way to visually show the relationships between the classes and how they are used within the project?!

Edited: 2008/10/24 8:40 PM

Based on the UML comment I attempted to turn to the built in Visual Studio class diagram to build a model of an application. I can give descriptions of each interface but still not sure that they are clearly connected.

Visual Studio Class Diagram

+1  A: 

UML interaction diagrams can explicitly show such relationships: this calls that ...

UML class diagrams can show both this class uses that interface and this interface is implemented by that class.

Now such diagrams are "point in time" statements about a particular choices made for a particular execution, which particular injections might have happened. So to some extent in providing the diagrams you are moving away from the generally flexible design you are using, however I can understand that folks do find such pictures helpful.

I try to think about aspects of design in relationship to the interfaces, I really should not need to understand "how" the methods described by an interface atually work, understand what the implementations are doing. Onde idea is that we do need to take a Black Box approach to our dependencies. So I'd recommend encouraging folks not to need such diagrams, instead to think in terms of responsibilities. (which is all very well until things don't work, then diagnosis may well require more) but consider: when you are using many operating system and .NET capabilities do you actually know what's really going on? Can you take the same mental approach with other parts of your applciation's code?

djna
This would assume that me or my team know's how to create and/or understand a UML diagram. Unless it's pretty simple to understand the diagram and the tools are freely available to create them this might be an issue.
Nathan Palmer
I have attempted to simply explain the interfaces but they seem to have a hard time understanding because they are trying to fit how the interface works within the workflow of the project.
Nathan Palmer
"Workflow of the project" do you mean in terms of developing code or in terms of what happens at run time in the application?
djna
"to show visually" requires some kind of diagram I guess? Is it better to devise your own or use a standard technique? You could learn a small subset of UML very quickly, a diagram with classed and interfaces on it is enough - two kinds of boxes and two kinds of lines - and you can draw them with Visio or Powerpoint if you can't find a UML tool you can afford.
djna
What I have found is that the developers working on the project need to understand what happens at run time in order to properly develop a service (1 class with 1 responsibility) within the project. So the answer to your two questions are "Yes."
Nathan Palmer
Hmmm, well there are two contexts, the things that use my component and the things my component uses. One really should not need to know very much about what else my users are doing. I have a contract and I fulfil it. end of story. As what I'm using, again I really don't think one should need to know the details. Perhaps this level of abstraction of thinkng comes with experience, but I do think it's a key to success with OO, at some point you have to respect encapsulation - you really don't need to know some stuff.
djna
Just to expand on that previous point, and answer the original question, this means that some very simple diagrams really should be sufficient.
djna
I would agree that it will be easier once they are more familiar with the design. But a simple visual overview page/description would be a big help.I looked at UML diagrams using Visio and it had quite a lot of stuff in there a bit more manual work to create it than I'd like. I'm playing around with using a class diagram with notes to see if that will fulfill my need. It seems similar to the UML but autogenerated from the code.
Nathan Palmer
+1  A: 

I tend to think about interfaces only when it comes to relationships so I can't really help you with broad overviews / class diagrams for concrete types. As someone has already pointed out, if you want to show concrete types on the diagram, it will only be relevant for a snapshot of one particular run -- it will change every time the object graph is wired differently.

I think it's generally more helpful to lay out the interfaces in diagrams, then browse the code base to find the implementations. One tip that makes code browsing much, much simpler:

Get the ReSharper plugin for Visual Studio and use the following shortcuts (when your caret is over a class/interface):

Alt + Home -- Go to base / interface

Alt + End -- Go to derived / types implementing interface

These two shortcuts are absolutely essential for browsing a codebase with a lot of loose coupling.

Mark Simpson
+1 for those great shortcuts. I have ReSharper and am currently deciding whether or not to but it for the team.
Nathan Palmer
I'd thoroughly recommend it. I've done my best to turn our work into R# land and nearly everyone agrees that it is an indispensable tool. :)
Mark Simpson