Class diagram is used to represent the static view of an application. The class diagrams are widely used in the modelling of object oriented systems because they are the only UML diagrams which can be mapped directly with object-oriented languages. Diagram supports to generate the class diagram shapes from business logic.
The UML class diagram shapes are explained as follows.
class
.name
, attributes
, and methods
of the class using the class property of node.name
, type
, and scope
properties allow you to define the name, data type, and visibility of the attribute.name
, parameters
, type
, and scope
properties allow you to define the name, parameter, return type, and visibility of the methods.<ejs-diagram id="container" width="100%" height="700px" nodes="@ViewBag.nodes">
</ejs-diagram>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;
namespace sample1.Controllers
{
public class NodeController : Controller
{
// GET: Node
public ActionResult Node()
{
List<DiagramNode> nodes = new List<DiagramNode>();
List<UMLProperty> patientProperty = new List<UMLProperty>();
patientProperty.Add(CreateUMLProperty("accepted", "Date"));
List<UMLMethods> patientMethods = new List<UMLMethods>();
patientMethods.Add(CreateUMLMethod("getHistory", "History"));
nodes.Add(
new DiagramNode()
{
Id = "Patient",
OffsetX = 200,
OffsetY = 250,
Shape = new UmlClassifierShapeModel()
{
Type = "UMLClassifier",
Class = new Class()
{
Name = "Patient",
Attributes = patientProperty,
Methods = patientMethods
},
},
}
);
ViewBag.Nodes = Nodes
return View();
}
public UMLProperty CreateUMLProperty(string name, string type)
{
UMLProperty property = new UMLProperty();
property.Name = name;
property.Type = type;
return property;
}
public UMLMethods CreateUMLMethod(string name, string type)
{
UMLMethods method = new UMLMethods();
method.Name = name;
method.Type = type;
return method;
}
}
public class UmlClassifierShapeModel
{
[DefaultValue(null)]
[HtmlAttributeName("type")]
[JsonProperty("type")]
public string Type
{
get;
set;
}
[DefaultValue(null)]
[HtmlAttributeName("class")]
[JsonProperty("class")]
public Class Class
{
get;
set;
}
}
public class Class
{
[DefaultValue(null)]
[HtmlAttributeName("name")]
[JsonProperty("name")]
public string Name
{
get;
set;
}
[DefaultValue(null)]
[HtmlAttributeName("attributes")]
[JsonProperty("attributes")]
public List<UMLProperty> Attributes
{
get;
set;
}
[DefaultValue(null)]
[HtmlAttributeName("methods")]
[JsonProperty("methods")]
public List<UMLMethods> Methods
{
get;
set;
}
}
public class UMLProperty
{
[DefaultValue(null)]
[HtmlAttributeName("name")]
[JsonProperty("name")]
public string Name
{
get;
set;
}
[DefaultValue(null)]
[HtmlAttributeName("type")]
[JsonProperty("type")]
public string Type
{
get;
set;
}
}
public class UMLMethods
{
[DefaultValue(null)]
[HtmlAttributeName("name")]
[JsonProperty("name")]
public string Name
{
get;
set;
}
[DefaultValue(null)]
[HtmlAttributeName("type")]
[JsonProperty("type")]
public string Type
{
get;
set;
}
}
}
interface
.name
, attributes
, and methods
of the interface using the interface property of the node.<ejs-diagram id="container" width="100%" height="700px" nodes="@ViewBag.nodes">
</ejs-diagram>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;
namespace sample1.Controllers
{
public class NodeController : Controller
{
// GET: Node
public ActionResult Node()
{
List<DiagramNode> nodes = new List<DiagramNode>();
List<UMLProperty> patientProperty = new List<UMLProperty>();
patientProperty.Add(CreateUMLProperty("accepted", "Date"));
List<UMLMethods> patientMethods = new List<UMLMethods>();
patientMethods.Add(CreateUMLMethod("getHistory", "History"));
nodes.Add(
new DiagramNode()
{
Id = "Patient",
OffsetX = 200,
OffsetY = 250,
Shape = new UmlClassifierShapeModel()
{
Type = "UMLClassifier",
Interface = new Interface()
{
Name = "Patient",
Attributes = patientProperty,
Methods = patientMethods
},
},
}
);
ViewBag.Nodes = Nodes
return View();
}
public UMLProperty CreateUMLProperty(string name, string type)
{
UMLProperty property = new UMLProperty();
property.Name = name;
property.Type = type;
return property;
}
public UMLMethods CreateUMLMethod(string name, string type)
{
UMLMethods method = new UMLMethods();
method.Name = name;
method.Type = type;
return method;
}
}
public class UmlClassifierShapeModel
{
[DefaultValue(null)]
[HtmlAttributeName("type")]
[JsonProperty("type")]
public string Type
{
get;
set;
}
[DefaultValue(null)]
[HtmlAttributeName("class")]
[JsonProperty("class")]
public Class Class
{
get;
set;
}
}
public class Interface
{
[DefaultValue(null)]
[HtmlAttributeName("name")]
[JsonProperty("name")]
public string Name
{
get;
set;
}
[DefaultValue(null)]
[HtmlAttributeName("attributes")]
[JsonProperty("attributes")]
public List<UMLProperty> Attributes
{
get;
set;
}
[DefaultValue(null)]
[HtmlAttributeName("methods")]
[JsonProperty("methods")]
public List<UMLMethods> Methods
{
get;
set;
}
}
public class UMLProperty
{
[DefaultValue(null)]
[HtmlAttributeName("name")]
[JsonProperty("name")]
public string Name
{
get;
set;
}
[DefaultValue(null)]
[HtmlAttributeName("type")]
[JsonProperty("type")]
public string Type
{
get;
set;
}
}
public class UMLMethods
{
[DefaultValue(null)]
[HtmlAttributeName("name")]
[JsonProperty("name")]
public string Name
{
get;
set;
}
[DefaultValue(null)]
[HtmlAttributeName("type")]
[JsonProperty("type")]
public string Type
{
get;
set;
}
}
}
enumeration
. Also, define the name and members of the enumeration using the enumeration property of the node.<ejs-diagram id="container" width="100%" height="700px" nodes="@ViewBag.nodes">
</ejs-diagram>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;
namespace sample1.Controllers
{
public class NodeController : Controller
{
// GET: Node
public ActionResult Node()
{
List<DiagramNode> nodes = new List<DiagramNode>();
List<UMLMembers> patientMembers = new List<UMLMembers>();
patientMembers.Add(CreateUMLMembers("Checking Account"));
patientMembers.Add(CreateUMLMembers("Savings Account"));
patientMembers.Add(CreateUMLMembers("Credit Account"));
nodes.Add(
new DiagramNode()
{
Id = "Patient",
OffsetX = 200,
OffsetY = 250,
Shape = new UmlClassifierShapeModel()
{
Type = "UMLClassifier",
Enumeration = new Enumeration()
{
Name = "AccountType",
Members = patientMembers
},
},
}
);
ViewBag.Nodes = Nodes
return View();
}
public UMLMembers CreateUMLMembers(string name)
{
UMLMembers members = new UMLMembers();
members.Name = name;
return members;
}
}
public class UmlClassifierShapeModel
{
[DefaultValue(null)]
[HtmlAttributeName("type")]
[JsonProperty("type")]
public string Type
{
get;
set;
}
[DefaultValue(null)]
[HtmlAttributeName("class")]
[JsonProperty("class")]
public Class Class
{
get;
set;
}
}
public class Enumeration
{
[DefaultValue(null)]
[HtmlAttributeName("name")]
[JsonProperty("name")]
public string Name
{
get;
set;
}
[DefaultValue(null)]
[HtmlAttributeName("members")]
[JsonProperty("members")]
public List<UMLMembers> Members
{
get;
set;
}
}
public class UMLMembers
{
[DefaultValue(null)]
[HtmlAttributeName("name")]
[JsonProperty("name")]
public string Name
{
get;
set;
}
}
}
Shape | Image |
---|---|
Association |
![]() |
Aggregation |
![]() |
Composition |
![]() |
Inheritance |
![]() |
Dependency |
![]() |
Association is basically a set of links that connects elements of an UML model. The type of association are as follows.
The association property allows you to define the type of association. The default value of association is “Directional”. The following code example illustrates how to create an association.
<ejs-diagram id="container" width="100%" height="700px" connectors="@ViewBag.connectors">
</ejs-diagram>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;
namespace sample1.Controllers
{
public class NodeController : Controller
{
// GET: Node
public ActionResult Node()
{
// Sets the Annotation for the Node
List<DiagramConnector> Connectors = new List<DiagramConnector>();
Connectors.Add(new DiagramConnector() {
Id = "connector",
SourcePoint = new DiagramPoint() { X = 100, Y = 100 },
TargetPoint = new DiagramPoint() { X = 200, Y = 200 },
Shape = new {type = "UmlClassifier", relationship="Association", association="BiDirectional"}
});
ViewBag.connectors = Connectors;
return View();
}
}
}
Aggregation is a binary association between a property and one or more composite objects which group together a set of instances. Aggregation is decorated with a hollow diamond. To create an aggregation shape, define the relationship as “aggregation”.
The following code example illustrates how to create an aggregation.
<ejs-diagram id="container" width="100%" height="700px" nodes="@ViewBag.connectors">
</ejs-diagram>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;
namespace sample1.Controllers
{
public class NodeController : Controller
{
// GET: Node
public ActionResult Node()
{
// Sets the Annotation for the Node
List<DiagramConnector> Connectors = new List<DiagramConnector>();
Connectors.Add(new DiagramConnector() {
Id = "connector",
SourcePoint = new DiagramPoint() { X = 100, Y = 100 },
TargetPoint = new DiagramPoint() { X = 200, Y = 200 },
Shape = new {type = "UmlClassifier", relationship="Aggregation" }
});
ViewBag.connectors = Connectors;
return View();
}
}
}
Composition is a “strong” form of “aggregation”. Composition is decorated with a black diamond. To create a composition shape, define the relationship property of connector as “composition”.
The following code example illustrates how to create a composition.
{% tab template= “diagram/umldiagramshapes”, es5Template=“es5composition” %}
<ejs-diagram id="container" width="100%" height="700px" connectors="@ViewBag.connectors">
</ejs-diagram>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;
namespace sample1.Controllers
{
public class NodeController : Controller
{
// GET: Node
public ActionResult Node()
{
// Sets the Annotation for the Node
List<DiagramConnector> Connectors = new List<DiagramConnector>();
Connectors.Add(new DiagramConnector() {
Id = "connector",
SourcePoint = new DiagramPoint() { X = 100, Y = 100 },
TargetPoint = new DiagramPoint() { X = 200, Y = 200 },
Shape = new {type = "UmlClassifier", relationship="Composition"}
});
ViewBag.connectors = Connectors;
return View();
}
}
}
Dependency is a directed relationship, which is used to show that some UML elements needs or depends on other model elements for specifications. Dependency is shown as dashed line with opened arrow. To create a dependency, define the relationship property of connector as “dependency”.
The following code example illustrates how to create an dependency.
<ejs-diagram id="container" width="100%" height="700px" connectors="@ViewBag.connectors">
</ejs-diagram>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;
namespace sample1.Controllers
{
public class NodeController : Controller
{
// GET: Node
public ActionResult Node()
{
// Sets the Annotation for the Node
List<DiagramConnector> Connectors = new List<DiagramConnector>();
Connectors.Add(new DiagramConnector() {
Id = "connector",
SourcePoint = new DiagramPoint() { X = 100, Y = 100 },
TargetPoint = new DiagramPoint() { X = 200, Y = 200 },
Shape = new {type = "UmlClassifier", relationship="Dependency"}
});
ViewBag.connectors = Connectors;
return View();
}
}
}
Inheritance is also called as “generalization”. Inheritance is a binary taxonomic directed relationship between a more general classifier (super class) and a more specific classifier (subclass). Inheritance is shown as a line with hollow triangle.
To create an inheritance, define the relationship as “inheritance”.
The following code example illustrates how to create an inheritance.
<ejs-diagram id="container" width="100%" height="700px" connectors="@ViewBag.connectors">
</ejs-diagram>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;
namespace sample1.Controllers
{
public class NodeController : Controller
{
// GET: Node
public ActionResult Node()
{
// Sets the Annotation for the Node
List<DiagramConnector> Connectors = new List<DiagramConnector>();
Connectors.Add(new DiagramConnector() {
Id = "connector",
SourcePoint = new DiagramPoint() { X = 100, Y = 100 },
TargetPoint = new DiagramPoint() { X = 200, Y = 200 },
Shape = new {type = "UmlClassifier", relationship="Inheritance"}
});
ViewBag.connectors = Connectors;
return View();
}
}
}
Multiplicity is a definition of an inclusive interval of non-negative integers to specify the allowable number of instances of described element. The type of multiplicity are as follows.
lowerBounds
and upperBounds
could be natural constants or constant expressions evaluated to natural (non negative) number. Upper bound could be also specified as asterisk ‘*’ which denotes unlimited number of elements. Upper bound should be greater than or equal to the lower bound.<ejs-diagram id="container" width="100%" height="700px" connectors="@ViewBag.connectors">
</ejs-diagram>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;
namespace sample1.Controllers
{
public class NodeController : Controller
{
// GET: Node
public ActionResult Node()
{
// Sets the Annotation for the Node
List<DiagramConnector> Connectors = new List<DiagramConnector>();
Connectors.Add(new DiagramConnector() {
Id = "connector",
SourcePoint = new DiagramPoint() { X = 100, Y = 100 },
TargetPoint = new DiagramPoint() { X = 200, Y = 200 },
Shape = new {type = "UmlClassifier", relationship="Dependency", multiplicity= new {type="OneToMany"}}
});
ViewBag.connectors = Connectors;
return View();
}
}
}
Activity diagram is basically a flowchart to represent the flow from one activity to another. The activity can be described as an operation of the system.
The purpose of an activity diagram can be described as follows.
To create a UmlActivity, define type as “UmlActivity” and the list of built-in shapes as demonstrated as follows and it should be set in the “shape” property.
Shape | Image |
---|---|
Action |
![]() |
Decision |
![]() |
MergeNode |
![]() |
InitialNode |
![]() |
FinalNode |
![]() |
ForkNode |
![]() |
JoinNode |
![]() |
TimeEvent |
![]() |
AcceptingEvent |
![]() |
SendSignal |
![]() |
ReceiveSignal |
![]() |
StructuredNode |
![]() |
Note |
![]() |
The following code illustrates how to create a UmlActivity shapes.
<ejs-diagram id="container" width="100%" height="700px" nodes="@ViewBag.nodes">
</ejs-diagram>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;
namespace sample1.Controllers
{
public class NodeController : Controller
{
// GET: Node
public ActionResult Node()
{
// Sets the Annotation for the Node
List<DiagramNode> Nodes = new List<DiagramNode>();
Nodes.Add(new DefaultNode()
{
Id = "Node1",
OffsetY = 100,
OffsetX = 100,
Height = 100,
Width = 100,
Shape = new {type="UmlActivity", shape="Action"}
});
ViewBag.nodes = Nodes;
return View();
}
}
}
To create an UmlActivity connector, define the type as “UmlActivity” and flow as either “Exception” or “Control” or “Object”.
The following code illustrates how to create a UmlActivity connector.
<ejs-diagram id="container" width="100%" height="700px" connectors="@ViewBag.connectors">
</ejs-diagram>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Diagrams;
namespace sample1.Controllers
{
public class NodeController : Controller
{
// GET: Node
public ActionResult Node()
{
// Sets the Annotation for the Node
List<DiagramConnector> Connectors = new List<DiagramConnector>();
Connectors.Add(new DiagramConnector() {
Id = "connector",
SourcePoint = new DiagramPoint() { X = 100, Y = 100 },
TargetPoint = new DiagramPoint() { X = 200, Y = 200 },
Shape = new {type = "UmlActivity", flow="Exception"}
});
ViewBag.connectors = Connectors;
return View();
}
}
}
You can edit the name, attributes, and methods of the class diagram shapes just double clicking, similar to editing a node annotation.
The following image illustrates how the text editor looks in an edit mode.