{"id":18798621,"url":"https://github.com/liteobject/demo.designpattern.decorator","last_synced_at":"2025-06-13T16:40:20.962Z","repository":{"id":90788563,"uuid":"546409723","full_name":"LiteObject/Demo.DesignPattern.Decorator","owner":"LiteObject","description":"An example of decorator design pattern in C#","archived":false,"fork":false,"pushed_at":"2023-08-01T16:01:40.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T18:22:01.435Z","etag":null,"topics":["csharp","decorator-pattern","design-patterns"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LiteObject.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-06T03:12:45.000Z","updated_at":"2023-08-01T16:04:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"29448155-9405-478f-9823-e8f6abcc57ef","html_url":"https://github.com/LiteObject/Demo.DesignPattern.Decorator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiteObject%2FDemo.DesignPattern.Decorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiteObject%2FDemo.DesignPattern.Decorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiteObject%2FDemo.DesignPattern.Decorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiteObject%2FDemo.DesignPattern.Decorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LiteObject","download_url":"https://codeload.github.com/LiteObject/Demo.DesignPattern.Decorator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239727055,"owners_count":19687099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","decorator-pattern","design-patterns"],"created_at":"2024-11-07T22:12:30.240Z","updated_at":"2025-02-19T20:15:58.336Z","avatar_url":"https://github.com/LiteObject.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# An Example of Decorator Design Pattern with C#\n\n## What is Decorator?\n\u003eThe Decorator design pattern attaches additional responsibilities to an object dynamically. This pattern provide a flexible alternative to subclassing for extending functionality.\n\n\n```mermaid\n\nclassDiagram\n    IComponent \u003c|-- ConcreteComponent   \n    IComponent \u003c|-- Decorator\n    IComponent \u003c--* Decorator:Ref to Component\n        \n    class IComponent { \n        \u003c\u003cInterface\u003e\u003e\n        +Operation()\n    }\n    \n    class ConcreteComponent {                \n        +Operation()\n    }\n\n    class Decorator {\n        \u003c\u003cAbstract\u003e\u003e\n        -Component\n        +Operation()\n    }\n\n    Decorator \u003c|-- ConcreteDecoratorA\n    Decorator \u003c|-- ConcreteDecoratorB\n\n    class ConcreteDecoratorA {      \n        -AddedState\n        +Operation()        \n    }\n\n    class ConcreteDecoratorB {      \n        +Operation()\n        +AddedBehavior()\n    }\n```\n* Component: \n  - Defines the interface for objects that can have responsibilities added to them dynamically\n  - Usually an abstract class or interface\n* ConcreteComponent: \n  - Defines an object to which additional responsibilities can be attached\n  - Inherits or implements the Component class/interface\n* Decorator: \n  - Maintains a reference to a Component object\n  - Usually an abstract class\n  - Inherits or implements the Component class/interface\n* ConcreteDecorator: \n  - Adds responsibilities to the component\n  - Inherits the Decorator\n\n---\n## Example One\n\n---\n## Example Two\nYou have an e-commerce website that sells various products. Each product has a price and some \nbasic information, such as the name and description. However, there are various discounts and \npromotions that can be applied to the products, such as a percentage discount, a buy-one-get-one-free offer, \nor a free gift with purchase.\n\nIn this scenario, the products are the Component objects, and the discounts and promotions are \nthe Decorator objects. You can create a base Product class that implements the basic information \nand price of the product. Then, you can create various Decorator classes that add different types \nof discounts and promotions to the product.\n\nFor example, you can create a `PercentageDiscountDecorator` class that adds a percentage discount \nto the product's price. You can also create a `FreeGiftDecorator` class that adds a free gift to \nthe product with a certain purchase amount. Finally, you can create a `BuyOneGetOneFreeDecorator` \nclass that adds a buy-one-get-one-free offer to the product.\n\nBy using the Decorator pattern in this scenario, you can add discounts and promotions to the \nproducts dynamically, without changing the underlying Product class or its interface. This allows \nyou to easily add or remove different types of discounts and promotions without affecting the \nexisting code.\n\n---\n\nIn summary, the Decorator pattern is useful in scenarios where you have a base object or component \nthat needs to be extended with additional functionality dynamically, without changing the underlying \nobject or its interface. This makes it a useful pattern in situations where you need to add or \nremove functionality from an object at runtime, while keeping the rest of the code unchanged.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliteobject%2Fdemo.designpattern.decorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliteobject%2Fdemo.designpattern.decorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliteobject%2Fdemo.designpattern.decorator/lists"}