Welcome to crc-diagram’s documentation!¶
crc-diagram is a generator of Class Responsibility Collaboration diagrams in python (more languages will be available soon) using DOT language.
What is CRC?¶
A Class Responsibility Collaboration (CRC) is a collection of standard index cards that have been divided into three sections.
How it works¶
Suppose that you have a project with two classes: HtmlToMarkdown and ImageUploader.
HtmlToMarkdown converts html files to markdown files, but HtmlToMarkdown does not know how to handle images. So it uses a collaborator called ImageUploader. ImageUploader knows how to handle images.
These classes could be write as follows:
class HtmlToMarkdown(object):
def __init__(self, image_uploader):
self.image_uploader = image_uploader
class ImageUploader(object):
pass
To make crc-diagram
generate the CRC cards just add docstrings to the classes with these notations:
class HtmlToMarkdown(object):
"""
@collaborator: ImageUploader
@responsibility: Convert html files to markdown
"""
def __init__(self, image_uploader):
self.image_uploader = image_uploader
class ImageUploader(object):
"""
@responsibility: Store images in the cloud
"""
pass
Note
Any of the notations can be ignored, as you can see in ImageUploader and you can add more than one collaborator or responsibility.
Save this code as markdown_converter.py and run the following command:
crc-diagram markdown_converter.py markdown_converter.png --view
This command will extract the CRC Cards and render as png. The --view
option is used to open the rendered diagram.
And the result is:
Extracting CRCs from modules¶
It’s also posible to extract CRCs from modules. The only thing you must do is to add docstrings to a module:
"""
file: module.py
@collaborator: A module collaborator
@responsibility: A module responsibility
"""
Installing¶
You can get the library directly from PyPI:
pip install crc-diagram
To render the diagrams you need to install dot:
Ubuntu/Debian:
apt-get update && apt-get install graphviz
Fedora/CentOS:
yum install graphviz