Skip to content

pugdevgit/PatternsCatalog

Repository files navigation

Design Patterns Catalog (Swift)

A comprehensive collection of classic Design Patterns implemented in Swift. This project demonstrates 22 fundamental patterns organized into three categories: Creational, Structural, and Behavioral patterns.

📋 Table of Contents

🎯 About

This repository serves as a practical reference and learning resource for software developers who want to understand and implement design patterns in Swift. Each pattern is implemented with clear, well-documented code that follows best practices and Swift idioms.

Design patterns are reusable solutions to common problems in software design. They represent best practices evolved over time by experienced software developers.

📦 Pattern Categories

Creational Patterns (5)

Patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation.

Structural Patterns (7)

Patterns that ease the design by identifying a simple way to realize relationships between entities.

Behavioral Patterns (10)

Patterns that identify common communication patterns between objects and realize these patterns.

📁 Project Structure

PatternsCatalog/
├── Creational/
│   ├── AbstractFactory.swift
│   ├── Builder.swift
│   ├── FactoryMethod.swift
│   ├── Prototype.swift
│   └── Singleton.swift
├── Structural/
│   ├── Adapter.swift
│   ├── Bridge.swift
│   ├── Composite.swift
│   ├── Decorator.swift
│   ├── Facade.swift
│   ├── Flyweight.swift
│   └── Proxy.swift
├── Behavioral/
│   ├── ChainOfResponsibility.swift
│   ├── Command.swift
│   ├── Iterator.swift
│   ├── Mediator.swift
│   ├── Memento.swift
│   ├── Observer.swift
│   ├── State.swift
│   ├── Strategy.swift
│   ├── TemplateMethod.swift
│   └── Visitor.swift
├── TestCreationalBundle/
├── TestStructuralBundle/
├── TestBehavioralBundle/
└── main.swift

💻 Requirements

  • Xcode: 12.0 or later
  • Swift: 5.0 or later
  • macOS: 10.15 or later

🚀 Usage

  1. Clone the repository:

    git clone https://github.com/yourusername/PatternsCatalog.git
    cd PatternsCatalog
  2. Open the project:

    open PatternsCatalog.xcodeproj
  3. Build and run:

    • Select the target scheme in Xcode
    • Press Cmd + R to build and run
    • Or run tests with Cmd + U
  4. Explore individual patterns: Each pattern file contains:

    • Detailed comments explaining the pattern
    • Complete implementation
    • Client code demonstrating usage

📚 Patterns Overview

Creational Patterns

Pattern Purpose
Abstract Factory Creates families of related objects without specifying their concrete classes
Builder Constructs complex objects step by step
Factory Method Defines an interface for creating objects, but lets subclasses decide which class to instantiate
Prototype Creates new objects by copying existing ones
Singleton Ensures a class has only one instance and provides a global access point

Structural Patterns

Pattern Purpose
Adapter Allows incompatible interfaces to work together
Bridge Separates abstraction from implementation
Composite Composes objects into tree structures to represent part-whole hierarchies
Decorator Adds new functionality to objects dynamically
Facade Provides a simplified interface to a complex subsystem
Flyweight Reduces memory usage by sharing common data between objects
Proxy Provides a surrogate or placeholder for another object

Behavioral Patterns

Pattern Purpose
Chain of Responsibility Passes requests along a chain of handlers
Command Encapsulates a request as an object
Iterator Provides a way to access elements of a collection sequentially
Mediator Reduces coupling between components by making them communicate through a mediator
Memento Captures and restores an object's internal state
Observer Defines a subscription mechanism to notify multiple objects about events
State Allows an object to alter its behavior when its internal state changes
Strategy Defines a family of algorithms and makes them interchangeable
Template Method Defines the skeleton of an algorithm in a base class
Visitor Separates algorithms from the objects on which they operate

🤝 Contributing

Contributions are welcome! If you'd like to add more patterns, improve existing implementations, or fix bugs:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingPattern)
  3. Commit your changes (git commit -m 'Add some AmazingPattern')
  4. Push to the branch (git push origin feature/AmazingPattern)
  5. Open a Pull Request

📄 License

This project is available for educational and reference purposes. Feel free to use and modify the code for your learning and projects.

📖 Further Reading


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages