Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

dynamic-class 是一個用於動態類別實例化的 TypeScript 函式庫,主要目標是更高效地實現 Design Pattern(設計模式)中的簡單工廠(Simple Factory)。透過動態類別裝飾器與動態類別工廠,開發者可以使用別名或類別名稱來動態建立類別實例、降低耦合度,提升擴展性,讓新類別可以無縫整合以及簡化 Factory Pattern 的實作,無需手動維護 Mapping Table。

NotificationsYou must be signed in to change notification settings

SteveLin100132/dynamic-class

Repository files navigation

dynamic-class 是一個用於動態類別實例化的 TypeScript 函式庫,主要目標是更高效地實現 Design Pattern(設計模式)中的簡單工廠(Simple Factory)。透過動態類別裝飾器與動態類別工廠,開發者可以使用別名或類別名稱來動態建立類別實例、降低耦合度,提升擴展性,讓新類別可以無縫整合以及簡化 Factory Pattern 的實作,無需手動維護 Mapping Table。

Install

npm i dynamic-class --save

Table of Contents

Feature

  • 提供動態實例類別
  • 可自訂類別別名,讓產生實例時,可以透過其他名稱實例對應物件

Usage

Dynamic Class Decorator

使用添@DynamicClass() 裝飾器,讓要動態實例的類別被記錄

import{DynamicClass}from'wistroni40-dynamic-class';@DynamicClass()exportclassCustomClassimplementsCustom{constructor(publicproperty:string){}publicmethod(){ ...}}

@DynamicClass()

該裝飾器提供以下配置

ParamterTypeDescription
aliasstring | string[]可提供單個或多個類別的別名
// 單個別名@DynamicClass({alias:'AliasName'})classMyClass{}// 多個別名@DynamicClass({alias:['AliasName1','AliasName2', ...]})classMyClass{}

Dynamic Class Factory

使用DynamicClassFactory 將指定的類別(以 String 給定類別名稱)實例

import{DynamicClassFactory}from'wistroni40-dynamic-class';constcustom=DynamicClassFactory.createInstance<Custom>('CustomClass','custom-property',);
createInstance()
ParamterTypeDescription
classNmaestring要實例的類別名稱
...argsany[]實例該類別所需的建構值參數,根據實際數量添加

Example

About

dynamic-class 是一個用於動態類別實例化的 TypeScript 函式庫,主要目標是更高效地實現 Design Pattern(設計模式)中的簡單工廠(Simple Factory)。透過動態類別裝飾器與動態類別工廠,開發者可以使用別名或類別名稱來動態建立類別實例、降低耦合度,提升擴展性,讓新類別可以無縫整合以及簡化 Factory Pattern 的實作,無需手動維護 Mapping Table。

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp