Skip to content

UML model and code examples of design patterns for Scala. The model is created with Astah.

License

Notifications You must be signed in to change notification settings

takaakit/design-pattern-examples-in-scala

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Design Pattern Examples in Scala

Model and code examples of GoF Design Patterns for Scala.
This project is available for the following objectives:

  • To understand GoF Design Pattern examples in Scala.
  • To understand the mapping between UML model and Scala code.
  • To try model-driven development (MDD) using Astah and m plus plug-in.

UML model example:

Scala code example:

// ˅
package structuralPatterns.composite

// ˄

class File(_name: String, _size: Int) extends FileSystemElement {
  // ˅
  
  // ˄

  private val name: String = _name

  private val size: Int = _size

  override def getName(): String = {
    // ˅
    name
    // ˄
  }

  override def getSize(): Int = {
    // ˅
    size
    // ˄
  }

  // Print this element with the "upperPath".
  override def print(upperPath: String): Unit = {
    // ˅
    println(f"$upperPath/$this")
    // ˄
  }

  // ˅
  
  // ˄
}

// ˅

// ˄

Installation

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.1.3-preview.1 or higher, and add it to Astah.
    How to add plugins to Astah

Scala Development Environment

  • Install Java SDK 21 or higher.
  • Install IntelliJ IDEA. Then, install Scala plugin in IntelliJ.
    Note: IntelliJ IDEA (with the Scala plugin) will automatically download and configure the required versions of the Scala SDK and sbt the first time you open this project. Simply click Download when the IDE prompts you, and continue once the setup completes.

Project Requirements

  • Scala: 3.7.1
  • SBT: 1.11.2 or higher
  • JavaFX: 21.0.2 (automatically managed by SBT)

Usage

Code Generation from UML

  1. Open the Astah file (model/DesignPatternExamplesInScala.asta).
  2. Select model elements on the model browser of Astah.
  3. 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

  1. Open the project root directory (design-pattern-examples-in-scala) in IntelliJ IDEA.
  2. Open Main.scala for the pattern you want to run, and click Run icon in the left gutter.

References

  • 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

License

This project is licensed under the Creative Commons Zero (CC0) license. The model and code are completely free to use.

CC0

Other Language Examples

C++, C#, Crystal, Go, Java, JavaScript, Kotlin, Python, Ruby, Swift, TypeScript

About

UML model and code examples of design patterns for Scala. The model is created with Astah.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages