Model and code examples of GoF Design Patterns for Kotlin.
This project is available for the following objectives:
- To understand GoF Design Pattern examples in Kotlin.
- To understand the mapping between UML model and Kotlin code.
- To try model-driven development (MDD) using Astah and m plus plug-in.
UML model example:
Kotlin code example:
package structuralPatterns.composite
// ˅
// ˄
class File(name: String, size: Int) : FileSystemElement() {
// ˅
// ˄
override val name: String = name
// ˅
// ˄
override val size: Int = size
// ˅
// ˄
// Print this element with the "upperPath".
override fun print(upperPath: String) {
// ˅
println("$upperPath/$this")
// ˄
}
// ˅
// ˄
}
// ˅
// ˄
UML Modeling Tool
- Download the modeling tool Astah UML/Professional ver.10.0.0 or higher, and install.
- Download m plus plug-in ver.3.0.0-preview or higher, and add it to Astah.
How to add plugins to Astah
Kotlin Development Environment
- Install Java SDK 11 or higher.
- Optionally, install an IDE (e.g. IntelliJ).
Code Generation from UML
- Open the Astah file (model/DesignPatternExamplesInKotlin.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 (if you use IntelliJ)
- Open the project root directory (design-pattern-examples-in-kotlin) 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, Ruby, Scala, Swift, TypeScript