Clojure Drawing UML

Source: Internet
Author: User
Tags sub command

Brief introduction

Using Clojure to encapsulate the use of Graphviz, the main implementation of UML is currently drawing

Use

Take the UML of command mode as an example to demonstrate the use of Cdraw

Installing Graphviz

Cdraw is a simple package for Graphviz, please first install the Graphviz

Add dependency
    • Create a new Clojure project using Leiningen UML
    • Add the following dependencies in the PROJECT.CLJ
[com.ivaneye/cdraw "0.2.0"]
Defining classes
    • Write the following code in Uml.core
(ns uml.core (: Require [cdraw.uml : Refer :all])) (defclass Client) (defclass inboker) (defclass Receiver {: M ["Action ()"]}) (defclass Command {: M ["Execute ()"]}) (defclass concretecommand {: F["state"] : M ["Execute () "]}  )
    • The first, two lines, introduced the Cdraw
    • Defclass defines the class, its fields (: f), and the method (: M), as follows:

Add dependency
    • Continue to add dependent code in Uml.core
 (defrelati On  Client :u  Receiver)   (defrelation  concretecommand :u  Receiver {:t  " Reveiver "} )   (defrelation  Client  :d  concretecommand)   (defrelation  Concretecommand :e  Command)   ( defrelation  Invoker :p  Command)   
    • Client associated receiver
    • Concretecommand Associated Receiver
    • Client Dependent Concretecommand
    • Concretecommand inherit command
    • Invoker Aggregation Command
关联  :u:d:p:c:e:i

Add label
    • Add the following code in the Uml.core
(label ConcreteCommand "receive-\\>Action()")
    • > Need to be escaped

Define a child package
(defsub "Sub Command" Command ConcreteCommand)
    • The first parameter is a child package name
    • Follow the classes that need to be included in the child package

Generated
    • Add the following code in the Uml.core
(watch (to-file "/t.dot") "/t.png")
    • To-file generate Graphviz-compliant dot file
    • Watch generates the desired final file, here is the PNG image generated
Final code
(ns uml.core (: Require [cdraw.uml : Refer :all]))(defclass Client)(defclass Invoker)(defclass Receiver {: M ["Action ()"]})(defclass Command {: M ["Execute ()"]})(defclass concretecommand {: F["state"] : M [" Execute () "]}  )(defrelation Client : U Receiver)(defrelation concretecommand : U Receiver {: t "Reveiver"})(defrelation Client :d concretecommand)(defrelation concretecommand : E Command)(defrelation Invoker :p Command)(label concretecommand "receive-\\>action ()")(defsub "Sub command" command Concretecommand)(watch (to-file "/t.dot") "/t.png")

Clojure Drawing UML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.