🎯 UVL2Pat

Universal Design Patterns Generator - From UVL Feature Models to Swift Code

Transform Universal Variability Language models into Swift design pattern implementations with future multi-language support

7+
Design Patterns
Swift
Primary Language
Pattern Variants
UVL
Feature Models

Features

🌐Supported Languages

🍎
Swift
✅ Available Now
🤖
Kotlin
🚧 Planned
Java
🚧 Planned
🎯
Dart
🚧 Planned
C#
🚧 Planned
🚀
More
🔮 Future
Current Focus: UVL2Pat currently supports Swift with a robust, extensible architecture designed for future multi-language expansion. The template system and UVL integration provide a solid foundation for adding support for Kotlin, Java, Dart, C#, and other languages.

📋Requirements

pip install jinja2 flamapy-fm pathlib click

📁Project Structure

UVL2Pat/
├── patterns/
│ ├── behavioral/
│ │ ├── strategy/
│ │ │ ├── strategy.uvl
│ │ │ ├── templates/
│ │ │ │ └── strategy.swift.j2
│ │ │ └── configurations/
│ │ │ ├── strategy.json
│ │ └── observer/
│ │ ├── observer.uvl
│ │ ├── templates/
│ │ │ └── observer.swift.j2
│ │ └── configurations/
│ │ ├── observer.json
│ ├── creational/
│ │ ├── factory_method/
│ │ │ ├── factory_method.uvl
│ │ │ ├── templates/
│ │ │ │ └── factory_method.swift.j2
│ │ │ └── configurations/
│ │ └── singleton/
│ │ ├── singleton.uvl
│ │ ├── templates/
│ │ │ └── singleton.swift.j2
│ │ └── configurations/
│ │ ├── singleton.json
│ └── structural/
│ ├── adapter/
│ ├── bridge/
│ └── decorator/

🛠️Installation

  1. Clone the repository:
    git clone https://github.com/trran/UVL2Pat.git
    cd UVL2Pat
  2. Install dependencies:
    pip install -r requirements.txt
  3. Install UVL2Pat:
    pip install -e .

🎯Quick Start

  1. Choose your pattern by modifying the variables in main.py:
    # Available categories and patterns:
    # behavioral: strategy, observer
    # creational: factory_method, singleton
    # structural: adapter, bridge, decorator

    general_group = "creational" # Change category
    pattern = "singleton" # Change pattern
  2. Run the generator:
    python main.py
  3. Find your generated Swift code in the output directory.

📝Available Patterns

🎭 Behavioral Patterns
🏭 Creational Patterns
🏗️ Structural Patterns

⚙️Configuration System

UVL Model
JSON Config
Template
Generated Code

Singleton Feature Model (singleton.uvl):

features
"Singleton Pattern" {abstract}
mandatory
"Initialization" {abstract}
alternative
"Eager"
"Lazy"
"Access Method" {abstract}
alternative
"getInstance()"
"Static Field"
"Property"
optional
"Thread Safety"
"Serialization Support"
String "Class Name"
String "Namespace"

constraints
"Eager" => !"Thread Safety"
"Static Field" => "Eager"
"Serialization Support" => "Thread Safety"

Configuration (singleton_threadsafe.json):

{
"Eager": false,
"Lazy": true,
"Initialization": true,
"Access Method": true,
"Thread Safety": true,
"Serialization Support": false,
"Class Name": "DatabaseManager",
"Namespace": "com.example.data",
"getInstance()": true,
"Static Field": false,
"Property": false
}

Swift Template (singleton.swift.j2):

{% set class_name = features.get("Class Name", "Singleton") %}
{% if features.get("Namespace") %}// Namespace: {{ features.get("Namespace") }}{% endif %}
import Foundation
{% if features.get("Thread Safety") and features.get("Lazy") %}
import Dispatch
{% endif %}

class {{ class_name }} {
{% if features.get("Eager") %}
static let shared = {{ class_name }}()
{% elif features.get("Lazy") %}
{% if features.get("Thread Safety") %}
private static var _instance: {{ class_name }}?
private static let queue = DispatchQueue(label: "{{ class_name.lower() }}.queue")
{% else %}
private static var _instance: {{ class_name }}?
{% endif %}
{% endif %}

private init() {
// Private initializer
}
}

Generated Swift Code:

// Namespace: com.example.data
import Foundation
import Dispatch

class DatabaseManager {
private static var _instance: DatabaseManager?
private static let queue = DispatchQueue(label: "databasemanager.queue")

private init() {
// Private initializer
}

static func getInstance() -> DatabaseManager {
return queue.sync {
if _instance == nil {
_instance = DatabaseManager()
}
return _instance!
}
}
}

📊Feature Analysis

Pattern Swift Support UVL Model Configurations Template Features
Singleton ✅ Complete 8 variants Thread Safety, Lazy/Eager, Access Methods
Observer ✅ Complete 6 variants Type Safety, Weak References, Combine
Strategy ✅ Complete 4 variants Protocol-based, Generic Implementation
Factory Method 🚧 In Progress 5 variants Generic Factories, Protocol Conformance
Decorator 🚧 In Progress 3 variants Protocol Extensions, Composition

🚨Constraint Validation

UVL Constraint Examples:
Validation Process:
UVL2Pat automatically validates configurations against UVL constraints before code generation, ensuring only valid pattern variants are created.

🤝Contributing

Adding New Patterns (Swift)

  1. Create UVL feature model: patterns/{category}/{pattern}/{pattern}.uvl
  2. Create Swift template: patterns/{category}/{pattern}/templates/{pattern}.swift.j2
  3. Add configuration examples: patterns/{category}/{pattern}/configurations/
  4. Write comprehensive tests for Swift implementation
  5. Update documentation

Preparing for Multi-Language Support

  1. Design language-agnostic UVL models
  2. Create template structure for future languages
  3. Implement language detection and routing
  4. Design extensible architecture for new language support

Swift-Specific Contributions

Development Process:
  1. Fork the repository: https://github.com/trran/UVL2Pat
  2. Create feature branch: git checkout -b feature/new-pattern
  3. Implement Swift patterns with tests
  4. Submit pull request with comprehensive documentation

🙋‍♂️Support & Community

🌟 Made with ❤️ for the Software Engineering Research Community 🌟

Transforming Feature Models into Code, One Pattern at a Time