Welcome to crc-diagram’s documentation!

https://coveralls.io/repos/github/IuryAlves/crc-diagram/badge.svg?branch=master https://travis-ci.org/IuryAlves/crc-diagram.svg?branch=master https://img.shields.io/badge/License-GPL%20v3-blue.svg
  1. What is CRC

  2. How it works

    2.1 Extracting CRCs from modules

  3. Installing

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.

http://agilemodeling.com/images/models/crcCardLayout.jpg
A class represents a collection of similar objects, a responsibility is something that a class knows or does, and a collaborator is another class that a class interacts with to fulfill its responsibilities.

More information.

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:

https://s27.postimg.org/6l3wauu4j/markdown_converter.png

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