# design_pattern_tutorial **Repository Path**: sanzk/design_pattern_tutorial ## Basic Information - **Project Name**: design_pattern_tutorial - **Description**: C# Design Patterns : A Tutorial 设计模式导论例程 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-01 - **Last Updated**: 2026-05-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Design Patterns Tutorial This project is a C# design patterns tutorial containing multiple sample applications demonstrating various commonly used object-oriented design patterns. Each sub-project illustrates specific programming concepts and the application of design patterns. ## Project Structure ### Console Applications | Project | Description | Patterns/Concepts Involved | |---------|-------------|----------------------------| | ConsoleApp1 | Example of inheritance between base class Person and derived class Employee | Abstract class, Inheritance, Method override | | ConsoleApp2 | Utility class for array list operations | Collections, Generics | | ConsoleApp3 | Basic console application | Basic structure | | ConsoleApp4 | Basic console application | Basic structure | | ConsoleApp5 | File reading operations | File I/O, StreamReader | | ConsoleApp6 | File processing class | File read/write, StreamWriter | ### Windows Forms Applications | Project | Description | Patterns/Concepts Involved | |---------|-------------|----------------------------| | WinFormsApp1 | Text case conversion | Delegate, Callback function | | WinFormsApp2 | Bit list operations | Indexer, Bitwise operations | | WinFormsApp3 | Drawing rectangles and squares | Inheritance, Method override | | WinFormsApp4 | Double-border rectangle | Difference between override and new | | WinFormsApp5 | Custom HiTextBox control | Custom control extension | | WinFormsApp6 | Shape graphics system | Abstract class, Polymorphism | | WinFormsApp7 | Name parsing factory | Simple Factory Pattern | | WinFormsApp8 | Butterfly calculator | Abstract Factory / Strategy Pattern | | WinFormsApp9 | Swimming race grouping | Factory Method Pattern | ## Core Design Pattern Examples ### 1. Abstract Class and Inheritance (ConsoleApp1) Demonstrates inheritance between the base class Person and derived class Employee: ```csharp public abstract class Person { public abstract string getJob(); } public class Employee : Person { public override string getJob() { /* ... */ } } ``` ### 2. Delegate Pattern (WinFormsApp1) Uses delegates to dynamically switch text formatting: ```csharp private delegate string fTxDelegate(string s); fTxDelegate ftx; // Select different processing methods based on radio button private void opCap_CheckedChanged(object sender, EventArgs e) { ftx = Capital1.fixText; } ``` ### 3. Indexer Pattern (WinFormsApp2) Implements indexer access for a bit list: ```csharp public class BitList { public int this[int index] { get { /* Get value of the specified bit */ } } } ``` ### 4. Abstract Class and Polymorphism (WinFormsApp6) Uses an abstract class to implement a graphics system: ```csharp public abstract class Shape { public abstract void draw(Graphics g); } public class Rectangle : Shape { public override void draw(Graphics g) { /* ... */ } } public class Circle : Shape { public override void draw(Graphics g) { /* ... */ } } ``` ### 5. Factory Pattern (WinFormsApp7) Simple factory pattern creates different types of name parsers based on input: ```csharp public class NameFactory { public Namer getName(string name) { // Determine whether the name is "first name + last name" or "last name + first name" based on comma position } } ``` ### 6. Factory Method Pattern (WinFormsApp9) Abstract factory method pattern handles swimming race grouping: ```csharp public abstract class Event { public abstract Seeding getSeeding(); } public class PrelimEvent : Event { public override Seeding getSeeding() { /* ... */ } } ``` ### 7. Strategy Pattern (WinFormsApp8) Uses an abstract class to implement different calculation strategies: ```csharp public abstract class Butterfly { abstract public void Execyte(Complex x, Complex y); } public class AddButterfly : Butterfly { public override void Execyte(Complex xi, Complex xj) { /* ... */ } } ``` ## Requirements - .NET Framework 4.x or higher - Visual Studio 2017 or higher - Windows operating system (required to run WinForms applications) ## Usage Instructions 1. Open the corresponding solution (.sln) file 2. Set the startup project 3. Press F5 or Ctrl+F5 to run Each sub-project can be run independently to learn specific design patterns. ## Learning Recommendations It is recommended to follow this learning sequence: 1. ConsoleApp1 – Understand basic inheritance concepts 2. WinFormsApp3 / WinFormsApp4 – Master the difference between override and new 3. WinFormsApp6 – Learn abstract classes and polymorphism 4. WinFormsApp7 – Understand the Factory pattern 5. WinFormsApp8 – Learn the Strategy pattern 6. WinFormsApp9 – Master the Factory Method pattern ## License This project is intended solely for learning and educational purposes.