Files
2026-01-09 03:04:13 +08:00

1.9 KiB

StrategySort-MVC-WinForms

A lightweight C# WinForms application that demonstrates string sorting using various algorithms. This project implements the Strategy Pattern for algorithm selection and the MVC (Model-View-Controller) Pattern to ensure a clean separation of concerns.

🚀 Features

  • Custom String Sorting: Input any text and sort its characters alphabetically.
  • Multiple Algorithms: Choose between Bubble Sort, Merge Sort, and Quick Sort.
  • Architectural Excellence: Built using MVC and Strategy design patterns.
  • Robustness: Includes a dedicated Unit Test project to ensure sorting accuracy.

🛠 Architecture

This project is designed with scalability and maintainability in mind:

1. Strategy Pattern

The sorting logic is decoupled from the main application. Each algorithm implements a common ISortStrategy interface, allowing the program to swap sorting behaviors at runtime without changing the client code.

2. MVC Pattern

  • Model: Handles the data logic and the execution of the sorting strategies.
  • View: The WinForms interface (TextSortWindow) which captures user input and displays results.
  • Controller: Acts as the bridge between the View and the Model, processing user commands and updating the UI.

📸 How It Works

  1. Input: Enter any string into the text box (e.g., github).
  2. Select Strategy: Choose a sorting algorithm from the ComboBox:
    • Bubble Sort
    • Merge Sort
    • Quick Sort
  3. Sort: Click the Sort button.
  4. Output: The sorted result (e.g., bgghitu) appears in the output label.

🧪 Unit Testing

The solution includes a Testing project using MSTest to validate the sorting logic.

  • Tests verify character sorting for empty strings, special characters, and long strings.
  • Ensures all three strategies return consistent results.