Model and code examples of GoF Design Patterns for Kotlin/Native.
This project is available for the following objectives:
- To understand GoF Design Pattern examples in Kotlin/Native.
- To understand the mapping between UML model and Kotlin/Native code.
- To try Model-Driven Development (MDD) using Astah and M PLUS plug-in.
NOTE: The code examples use GTK4 and work on Ubuntu 22 (x86_64) and Fedora 36 (x86_64).
UML model example:
Kotlin/Native code example:
package structuralPatterns.composite
// ˅
// ˄
abstract class FileSystemElement {
// ˅
// ˄
abstract val name: String
// ˅
// ˄
abstract val size: Int
// ˅
// ˄
// Print this element with the "upperPath".
abstract fun print(upperPath: String)
override fun toString(): String {
// ˅
return "$name ($size)"
// ˄
}
// ˅
// ˄
}
// ˅
// ˄
NOTE: The code examples work on Ubuntu 22 (x86_64) and Fedora 36 (x86_64).
UML Modeling Tool
- Download the modeling tool Astah UML or Professional, and install.
- Download M PLUS plug-in ver.2.8.2 or higher, and add it to Astah.
How to add plugins to Astah
Kotlin/Native Development Environment
- Download and install IntelliJ.
- Run the following command to install GTK4 development libraries.
Ubuntu 22Fedora 36sudo apt install libgtk-4-dev libncurses5 gcc-multilib
sudo dnf install gtk4-devel ncurses-compat-libs
NOTE: The code examples work on Ubuntu 22 (x86_64) and Fedora 36 (x86_64).
Code Generation from UML
- Open the Astah file (model/DesignPatternExamplesInKotlinNative.asta).
- Select model elements on the model browser of Astah.
- Click the Generate Code button.
The generated code has User Code Area. The User Code Area is the area enclosed by "˅" and "˄". Handwritten code written in the User Code Area remains after a re-generation. View code example.
For detailed usage of the tools, please see Astah Manual and M PLUS plug-in Tips.
Build and Run
- Open the project root directory (design-pattern-examples-in-kotlin-native) in IntelliJ.
- Open
Main.kt
for the pattern you want to run, and clickRun
icon in the left gutter.
- Gamma, E. et al. Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley, 1994
- Hiroshi Yuki. Learning Design Patterns in Java [In Japanese Language], Softbank publishing, 2004
This project is licensed under the Creative Commons Zero (CC0) license. The model and code are completely free to use.
C++, C#, Crystal, Go, Java, JavaScript, Python, Kotlin/JVM, Ruby, Scala, Swift, TypeScript