Knex.js based query builder to interpret design patterns in MermaidJS.
You can try out the ParseidonJS node module at the link below!
The database includes 4 tables, as shown in the diagram before. This database is queried to check for design patterns and relations in the class diagram.
classDiagram
direction LR
Relations "1" --> "2" Classes
Classes "1" --> "0..*" Members
Classes "1" --> "0..*" Methods
class Relations {
int id
String first_class
String relation
String second_class
}
class Classes {
String id
int[] members
int[] methods
String type
}
class Members {
int id
String type
String name
String accessibility
String classifier
}
class Methods {
int id
String returnType
String name
String parameters
String accessibility
String classifier
}
For the moment, ParseidonJS supports these design patterns software design patterns:
- Singleton class has private static instance of own class
- Singleton class has a private constructor
- Singleton class has public static method returning the singleton class instance
- There is no instance of the singleton class in any other class
classDiagram
Animal <|-- Duck
Animal <|-- Fish
Animal <|-- Zebra
Singleton --> Singleton
Animal : +int age
Animal : +String gender
Animal: +isMammal()
Animal: +mate()
class Duck{
+String beakColor
+swim()
+quack()
}
class Fish{
-int sizeInFeet
-canEat()
}
class Zebra{
+bool is_wild
+run()
}
class Singleton{
-Singleton singleton$
-Singleton()
+getInstance()$ Singleton
}
classDiagram
Animal <|-- Duck
Animal <|-- Fish
Animal <|-- Zebra
Singleton --> Singleton
Animal : +int age
Animal : +String gender
Animal: +isMammal()
Animal: +mate()
class Duck{
+String beakColor
+swim()
+quack()
}
class Fish{
-int sizeInFeet
-canEat()
}
class Zebra{
+bool is_wild
+run()
}
class Singleton{
-Singleton singleton$
-Singleton()
+getInstance()$ Singleton
}
- Have a "product" interface implemented by at least 1 "product'
- Have an abstract "creator" class with abstract method that returns "product" interface and at least 1 other method
- Have at least one class inheriting from "creator" class
classDiagram
direction RL
class Dialog {
<<abstract>>
+render()
+createButton()* Button
}
class Button {
<<interface>>
+render()
+onClick()
}
class WindowsDialog {
+createButton(): Button
}
WindowsDialog --|> Dialog
WindowsButton ..|> Button
Dialog --> Button
classDiagram
direction RL
class Dialog {
<<abstract>>
+render()
+createButton()* Button
}
class Button {
<<interface>>
+render()
+onClick()
}
class WindowsDialog {
+createButton(): Button
}
WindowsDialog --|> Dialog
WindowsButton ..|> Button
Dialog --> Button
- Strategy interface with 1 method ( Strategy method )
- Context class with private Strategy interface member
- One class implementing the Strategy interface
classDiagram
Context o-- Strategy
Context --> Strategy
ConcreteStrategy ..|> Strategy
class Strategy {
<<interface>>
+execute(data)
}
class ConcreteStrategy {
+execute(data)
}
class Context {
-Strategy strategy
+setStrategy(strategy)
+doSomething()
}
classDiagram
Context o-- Strategy
Context --> Strategy
ConcreteStrategy ..|> Strategy
class Strategy{
<<interface>>
+execute(data)
}
class ConcreteStrategy{
+execute(data)
}
class Context{
-Strategy strategy
+setStrategy(strategy)
+doSomething()
}
- Adapter class that associates with the service and implements the client interface
- Service class, the client can't use it directly. Adapter class has an instance of it
classDiagram
SquarePegAdapter ..|> RoundPeg
SquarePegAdapter --> SquarePeg
class SquarePegAdapter{
-SquarePeg peg
+SquarePegAdapter(SquarePeg peg)
+getRadius() int
}
class SquarePeg{
-int width
+SquarePeg(int width)
+getWidth() int
}
class RoundPeg{
<<interface>>
+getRadius() int
}
classDiagram
SquarePegAdapter ..|> RoundPeg
SquarePegAdapter --> SquarePeg
class SquarePegAdapter{
-SquarePeg peg
+SquarePegAdapter(SquarePeg peg)
+getRadius() int
}
class SquarePeg{
-int width
+SquarePeg(int width)
+getWidth() int
}
class RoundPeg{
<<interface>>
+getRadius() int
}
- Component interface with at least one method
- Two classes implementing the Component interface (Leaf and Container)
- One class(Container) with an array of interface type, methods to add and remove members of the array
classDiagram
Dot ..|> Graphic
CompoundGraphic ..|> Graphic
class Graphic {
<<interface>>
+move(int x,int y)
+draw()
}
class Dot {
+Dot(int x, int y)
+move(int x, int y)
+draw()
}
class CompoundGraphic {
-Graphic[] children
+add(Graphic child)
+remove(Graphic child)
+move(int x, int y)
+draw()
}
classDiagram
Dot ..|> Graphic
CompoundGraphic ..|> Graphic
class Graphic {
<<interface>>
+move(int x,int y)
+draw()
}
class Dot {
+Dot(int x, int y)
+move(int x, int y)
+draw()
}
class CompoundGraphic {
-Graphic[] children
+add(Graphic child)
+remove(Graphic child)
+move(int x, int y)
+draw()
}
- Interface implemented by at least two classes (Proxy and Service)
- Proxy class has instance of service class
- Proxy class constructor has parameter of type service class
- Proxy class has association to Service
classDiagram
class ThirdPartyYTLib{
+listVideos()
+getVideoInfo(id)
+downloadVideo(id)
}
class CachedYTClass{
-ThirdPartyYTClass service
+CachedYTClass(ThirdPartyYTClass s)
+listVideos()
+getVideoInfo(id)
+downloadVideo(id)
}
class ThirdPartyYTClass{
+listVideos()
+getVideoInfo(id)
+downloadVideo(id)
}
CachedYTClass ..|> ThirdPartyYTLib
ThirdPartyYTClass ..|> ThirdPartyYTLib
CachedYTClass o--> ThirdPartyYTLib
classDiagram
class ThirdPartyYTLib{
+listVideos()
+getVideoInfo(id)
+downloadVideo(id)
}
class CachedYTClass{
-ThirdPartyYTClass service
+CachedYTClass(ThirdPartyYTClass s)
+listVideos()
+getVideoInfo(id)
+downloadVideo(id)
}
class ThirdPartyYTClass{
+listVideos()
+getVideoInfo(id)
+downloadVideo(id)
}
CachedYTClass ..|> ThirdPartyYTLib
ThirdPartyYTClass ..|> ThirdPartyYTLib
CachedYTClass o--> ThirdPartyYTLib
- Interface (Subscriber) implemented by at least one class (concrete subscribers)
- Interface has aggregation with a class (Publisher)
- Publisher class has array of interface (Subscriber) type
- Publisher class has two methods with parameter of interface (Subscriber) type
classDiagram
class EventManager{
-EventListeners listeners[]
+subscribe(EventListeners l)
+unsubscribe(EventListeners l)
+notify(EventType event, String data)
}
class EventListeners{
<<interface>>
+update(String filename)
}
class EmailAlertsListener{
+update(String filename)
}
class LoggingListener{
+update(String filename)
}
EventManager o--> EventListeners
EmailAlertsListener ..|> EventListeners
LoggingListener ..|> EventListeners
classDiagram
class EventManager{
-EventListeners listeners[]
+subscribe(EventListeners l)
+unsubscribe(EventListeners l)
+notify(EventType event, String data)
}
class EventListeners{
+update(String filename)
}
class EmailAlertsListener{
+update(String filename)
}
class LoggingListener{
+update(String filename)
}
EventManager o--> EventListeners
EmailAlertsListener ..|> EventListeners
LoggingListener ..|> EventListeners
classDiagram
class EventManager{
-EventListeners listeners[]
+subscribe(EventListeners l)
+unsubscribe(EventListeners l)
+notify(EventType event, String data)
}
class EventListeners{
+update(String filename)
}
class EmailAlertsListener{
+update(String filename)
}
class LoggingListener{
+update(String filename)
}
EventManager o--> EventListeners
EmailAlertsListener ..|> EventListeners
LoggingListener ..|> EventListeners