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

takaakit / design-pattern-examples-in-python

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

Programming Languages

python
139335 projects - #7 most used programming language

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

design-pattern-examples-in-crystal
UML model and code examples of design patterns for Crystal. The model is created with Astah.
Stars: ✭ 51 (+88.89%)
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 (-14.81%)
Mutual labels:  uml, design-patterns, gof
Uml Diagram For Python Design Pattern Examples
UML diagram list of GoF design pattern examples written in Python.
Stars: ✭ 40 (+48.15%)
Mutual labels:  uml, design-patterns
java-design-patterns
设计模式专题,共 23 种设计模式。GOF design patterns,implement of Java。
Stars: ✭ 32 (+18.52%)
Mutual labels:  design-patterns, gof
design-patterns-java
📗 Classic OOP Design Patterns from GoF, implemented in Java.
Stars: ✭ 25 (-7.41%)
Mutual labels:  design-patterns, gof
Designpattern
设计模式
Stars: ✭ 66 (+144.44%)
Mutual labels:  uml, design-patterns
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 (+851.85%)
Mutual labels:  design-patterns, gof
Examplesofdesignpatterns
设计模式的总结与例子(有XMind,Uml图和详细代码实现说明)
Stars: ✭ 265 (+881.48%)
Mutual labels:  uml, design-patterns
design-patterns-cookbook
Design Patterns in simple words with examples on PHP
Stars: ✭ 26 (-3.7%)
Mutual labels:  design-patterns, gof
guile-smc
GNU Guile State Machine Compiler
Stars: ✭ 15 (-44.44%)
Mutual labels:  uml
spark-design-system
Spark Design System
Stars: ✭ 101 (+274.07%)
Mutual labels:  design-patterns
go-design-pattern
go的设计模式实例
Stars: ✭ 45 (+66.67%)
Mutual labels:  design-patterns
IdeaSingletonInspection
Inspection for detecting of inappropriate use of Singleton pattern in Java
Stars: ✭ 14 (-48.15%)
Mutual labels:  design-patterns
Design-Patterns
A collection of popular design patterns with video and text explanations
Stars: ✭ 159 (+488.89%)
Mutual labels:  design-patterns
design-patterns-swift
Design Pattern Examples in Swift
Stars: ✭ 95 (+251.85%)
Mutual labels:  design-patterns
vala
design-patterns-for-humans in Vala (programming language)
Stars: ✭ 52 (+92.59%)
Mutual labels:  design-patterns
LearningPoint
A repository for learning different technologies, frameworks, features......
Stars: ✭ 66 (+144.44%)
Mutual labels:  design-patterns
work
A compact library for tracking and committing changes to your entities.
Stars: ✭ 50 (+85.19%)
Mutual labels:  design-patterns
here-we-go
Contains hundreds of samples for learning Go.
Stars: ✭ 93 (+244.44%)
Mutual labels:  design-patterns
OOP-Design-Patterns
MET CS665 - OOP Design Patterns Code Examples
Stars: ✭ 74 (+174.07%)
Mutual labels:  design-patterns

Design Pattern Examples in Python

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

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

UML model example:

Python code example:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ˅
from structural_patterns.composite.file_system_element import FileSystemElement

# ˄


class File(FileSystemElement):
    # ˅

    # ˄

    def __init__(self, name, size):

        self.__name = name

        self.__size = size

        # ˅
        super().__init__()
        # ˄

    def get_name(self):
        # ˅
        return self.__name
        # ˄

    def get_size(self):
        # ˅
        return self.__size
        # ˄

    # Print this element with the "upper_path".
    def print(self, upper_path):
        # ˅
        print(upper_path + '/' + self.to_string())
        # ˄

    # ˅

    # ˄


# ˅

# ˄

Installation

UML Modeling Tool

Python Development Environment

  • Install Python with tkinter included. The operation has been confirmed in Python 3.7.0.
  • Optionally, install an IDE (e.g. PyCharm).

Usage

Code Generation from UML

  1. Open the Astah file (model/DesignPatternExamplesInPython.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.

Run (if you use PyCharm)

  1. Open the project root directory (design-pattern-examples-in-python) in PyCharm.
  2. Open main.py 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

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#, Crystal, Go, Java, JavaScript, Kotlin, 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].