All Projects → takaakit → design-pattern-examples-in-crystal

takaakit / design-pattern-examples-in-crystal

Licence: CC0-1.0 license
UML model and code examples of design patterns for Crystal. The model is created with Astah.

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to design-pattern-examples-in-crystal

design-pattern-examples-in-python
UML model and code examples of design patterns for Python. The model is created with Astah.
Stars: ✭ 27 (-47.06%)
Mutual labels:  uml, design-patterns, gof, astah, m-plus-plugin
uml-diagram-for-kotlin-design-pattern-examples
UML diagram list of GoF design pattern examples written in Kotlin.
Stars: ✭ 23 (-54.9%)
Mutual labels:  uml, design-patterns, gof
design-patterns-typescript
Nessa seção falamos sobre 22 (de 23) padrões de projeto da GoF. Todos descritos em vídeo, com teoria e prática + exemplos de código.
Stars: ✭ 257 (+403.92%)
Mutual labels:  design-patterns, gof
design-patterns-java
📗 Classic OOP Design Patterns from GoF, implemented in Java.
Stars: ✭ 25 (-50.98%)
Mutual labels:  design-patterns, gof
java-design-patterns
设计模式专题,共 23 种设计模式。GOF design patterns,implement of Java。
Stars: ✭ 32 (-37.25%)
Mutual labels:  design-patterns, gof
Examplesofdesignpatterns
设计模式的总结与例子(有XMind,Uml图和详细代码实现说明)
Stars: ✭ 265 (+419.61%)
Mutual labels:  uml, design-patterns
Uml Diagram For Python Design Pattern Examples
UML diagram list of GoF design pattern examples written in Python.
Stars: ✭ 40 (-21.57%)
Mutual labels:  uml, design-patterns
Designpattern
设计模式
Stars: ✭ 66 (+29.41%)
Mutual labels:  uml, design-patterns
design-patterns-cookbook
Design Patterns in simple words with examples on PHP
Stars: ✭ 26 (-49.02%)
Mutual labels:  design-patterns, gof
design-patterns
Grokking design patterns in python
Stars: ✭ 24 (-52.94%)
Mutual labels:  design-patterns
JavaScript-design-patterns
Examples of popular design patterns in JavaScript
Stars: ✭ 41 (-19.61%)
Mutual labels:  design-patterns
uml2solidity
A uml profile and a set of acceleo code generators to model smart contracts in uml and generate solidity code.
Stars: ✭ 35 (-31.37%)
Mutual labels:  uml
PlantUml-Language-Service
PlantUml Language Service extension for Visual Studio 2017 and 2019
Stars: ✭ 24 (-52.94%)
Mutual labels:  uml
jw-design-library
A library of product design patterns comprised of code, usage and guidelines.
Stars: ✭ 16 (-68.63%)
Mutual labels:  design-patterns
design-patterns-php
All Design Patterns Samples in PHP
Stars: ✭ 43 (-15.69%)
Mutual labels:  design-patterns
notes
My personal tutorials and notes.
Stars: ✭ 34 (-33.33%)
Mutual labels:  design-patterns
Design-Patterns-In-Swift-CN
设计模式(Swift 5.0 实现)- 中文版
Stars: ✭ 290 (+468.63%)
Mutual labels:  design-patterns
PlantUML-colors
This script is to show all named color suggested by PlantUML
Stars: ✭ 52 (+1.96%)
Mutual labels:  uml
design-patterns-explained
Explanation for most of the well-known design patterns with examples and figures.
Stars: ✭ 18 (-64.71%)
Mutual labels:  design-patterns
solidity-diagram-gen
UML class diagram generator for solidity contracts
Stars: ✭ 33 (-35.29%)
Mutual labels:  uml

Design Pattern Examples in Crystal

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

  • To understand GoF Design Pattern examples in Crystal.
  • To understand the mapping between UML model and Crystal code.
  • To try Model-Driven Development (MDD) using Astah and M PLUS plug-in.

UML model example:

Crystal code example:

# ˅
require "./file_system_element"

# ˄

# Since class name of "File" can not be used duplicately, the class name is "File_".
class File_ < FileSystemElement
  # ˅

  # ˄

  @name : String

  @size : Int32

  def initialize(name : String, size : Int32)
    # ˅
    @name = name
    @size = size
    # ˄
  end

  def name : String
    # ˅
    return @name
    # ˄
  end

  def size : Int32
    # ˅
    return @size
    # ˄
  end

  # Print this element with the "upperPath".
  def print(upper_path : String)
    # ˅
    puts "#{upper_path}/#{self.to_s}"
    # ˄
  end

  # ˅
  # ˄
end

# ˅
# ˄

Installation on Ubuntu

This has been confirmed on Ubuntu 22.04 / 20.04.2 / 18.04.5, not confirmed on macOS and Windows.

UML Modeling Tool

Crystal Development Environment

  • Install Crystal ver.1.0.0 or higher.
  • Download and install VS Code.
  • Install Crystal Language and Native Debug extensions for VS Code.
  • Run this command to install the GTK and GDK development packages.
    Ubuntu 20.04 / 18.04
    sudo apt-get install libgirepository1.0-dev libgtk-3-dev libcairo-gobject2 gir1.2-freedesktop
    Ubuntu 22.04
    sudo apt-get install libgirepository1.0-dev libgtk-3-dev libcairo-gobject2 gir1.2-freedesktop
    sudo apt-get install gcc pkg-config git tzdata libpcre3-dev libevent-dev libyaml-dev libgmp-dev libssl-dev libxml2-dev
  • Run this command in the project root directory to install crystal-gobject and cairo-gobject shards.
    shards install
    Note: The following error (File::AlreadyExistsError) occurs when running the shards command, but the installation seems to succeed.
    Unhandled exception: Error creating symlink: '..' -> '/path_to_app/lib/cairo-gobject/lib': File exists (File::AlreadyExistsError)
  • If you use Ubuntu18.04 based distributives, uncomment Rectangle structure in lib/cairo-gobject/src/cairo/lib_cairo.cr file (lines 7...12). Source: cairo-gobject

Usage on Ubuntu

This has been confirmed on Ubuntu 22.04 / 20.04.2 / 18.04.5, not confirmed on macOS and Windows.

Code Generation from UML

  1. Open the Astah file (model/DesignPatternExamplesInCrystal.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 (in Debug Mode)

  1. Open the workspace file (design-pattern-examples-in-crystal.code-workspace) in VS Code.
  2. Open main.cr for the pattern you want to run, and click Run > Start Debugging (or press F5).

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

Licence

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#, Go, Java, JavaScript, Kotlin, Python, Ruby, Scala, Swift, TypeScript

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].