Λογότυπο Hor Strategy Pattern

Hor Strategy Pattern

Οργανισμός
openreachtech
hor-strategy-pattern

Implement the strategy pattern as a trio of a base processor class, one concrete subclass per variant, and a bulk loader that auto-discovers the subclasses from a directory and picks one by a dispatch getter. Use this skill whenever the user asks to replace an else-if / switch chain that dispatches on a "type" string with pluggable processor classes, or to add a new event / webhook / message handler that must be auto-discovered.

Επισκόπηση

Εκδότηςopenreachtech
Αποθετήριοhora-skills-ort-renchan
Όνομα δεξιότηταςhor-strategy-pattern
Αστέρια
32
Forks
0
Συνοδευτικά αρχεία
Μόνο οδηγίες
Άδεια χρήσηςApache-2.0
Σύνδεσμοι
  • Οδηγίες σε Markdown

    Ένα αρχείο SKILL.md που το μοντέλο φορτώνει όταν χρειάζεται, ώστε να καταναλώνει token μόνο όταν ένα αίτημα είναι πράγματι σχετικό.

  • Λειτουργεί με οποιοδήποτε LLM

    Οι δεξιότητες AI είναι απλό Markdown, όχι κώδικας για συγκεκριμένο πάροχο, επομένως αυτή η δεξιότητα λειτουργεί με GPT, Claude, Gemini, Grok ή ένα τοπικό μοντέλο.

  • Αυτοτελής

    Όλα όσα χρειάζεται το μοντέλο περιλαμβάνονται στις οδηγίες — χωρίς επιπλέον αρχεία για συγχρονισμό.

  • Ανοιχτού κώδικα

    Δημοσιεύτηκε από openreachtech στο GitHub. Διαβάστε το πηγαίο περιεχόμενο πριν εγκαταστήσετε τη δεξιότητα.

Εγκατάσταση

Εγκαταστήστε τη δεξιότητα AI Hor Strategy Pattern στο TypingMind για να τη χρησιμοποιείτε με οποιοδήποτε LLM ή προσθέστε τη σε άλλον πράκτορα AI που διαβάζει αρχεία SKILL.md.

1

Εγκατάσταση στο TypingMind

Το TypingMind εγκαθιστά μια δεξιότητα απευθείας από τον φάκελό της στο GitHub — διαβάζει το SKILL.md, συγκεντρώνει τα συνοδευτικά αρχεία σε πακέτο και αποθηκεύει το αποτέλεσμα τοπικά.

  1. Ανοίξτε την εφαρμογή και μεταβείτε στα Πρόσθετα → Δεξιότητες.
  2. Επιλέξτε «Εγκατάσταση από GitHub».
  3. Επικολλήστε το παρακάτω URL του φακέλου της δεξιότητας και επιβεβαιώστε.
    https://github.com/openreachtech/hora-skills-ort-renchan/tree/main/kit/skills/hor-strategy-pattern
  4. Ενεργοποιήστε τη δεξιότητα σε κάθε συνομιλία όπου θέλετε να είναι διαθέσιμη.
Πρόσθετα → Δεξιότητες → Νέα δεξιότητα → Από URL του GitHub, έπειτα επικολλήστε το URL του φακέλου και πατήστε «Συνέχεια».
2

Εγκατάσταση σε άλλον πράκτορα AI

Κάθε πράκτορας AI που διαβάζει τη μορφή Agent Skills μπορεί να χρησιμοποιήσει αυτή τη δεξιότητα — αντιγράψτε τον φάκελο στον κατάλογο δεξιοτήτων του.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/openreachtech/hora-skills-ort-renchan.git /tmp/hora-skills-ort-renchan
mkdir -p .claude/skills
cp -r /tmp/hora-skills-ort-renchan/kit/skills/hor-strategy-pattern .claude/skills/hor-strategy-pattern
Επανεκκινήστε το Claude Code μετά την αντιγραφή, ώστε να εντοπίσει τη νέα δεξιότητα.

Χρησιμοποιήστε τη στο TypingMind

Ενεργοποιήστε τη δεξιότητα Hor Strategy Pattern σε οποιαδήποτε συνομιλία στο TypingMind και το μοντέλο αναλαμβάνει τα υπόλοιπα. Το όνομα και η περιγραφή της περιλαμβάνονται στην προτροπή συστήματος και, μόλις προκύψει ένα σχετικό αίτημα, το μοντέλο φορτώνει μόνο του τις πλήρεις οδηγίες — δεν χρειάζεται ποτέ να την καλείτε χειροκίνητα και δεν καταναλώνει token μέχρι να χρησιμοποιηθεί πραγματικά.

Το μοντέλο φορτώνει αυτόματα τη δεξιότητα Hor Strategy Pattern μόλις λάβει ένα σχετικό αίτημα.

Λειτουργεί με οποιοδήποτε μοντέλο AI

Οι δεξιότητες AI είναι απλές οδηγίες Markdown και όχι κώδικας για συγκεκριμένο πάροχο, οπότε η δεξιότητα Hor Strategy Pattern δεν περιορίζεται στο μοντέλο για το οποίο γράφτηκε. Εγκαταστήστε τη μία φορά στο TypingMind και χρησιμοποιήστε τη με GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama ή ένα τοπικό μοντέλο που εκτελείτε εσείς — πάντα με τα δικά σας κλειδιά API.

  • Φόρτωση μόνο όταν χρειάζεται

    Η προτροπή συστήματος περιλαμβάνει μόνο το όνομα και την περιγραφή. Οι οδηγίες ανακτώνται με το πρώτο σχετικό αίτημα, οπότε μια δεξιότητα που δεν χρησιμοποιείται δεν έχει κόστος.

  • Αλλάξτε μοντέλα κατά τη συνομιλία

    Επειδή η δεξιότητα αποτελείται από οδηγίες και όχι από κώδικα, η αλλαγή μοντέλου δεν επηρεάζει τη λειτουργία της — το επόμενο μοντέλο διαβάζει το ίδιο αρχείο SKILL.md.

Οδηγίες δεξιότητας

Αυτό είναι το περιεχόμενο του αρχείου SKILL.md που φορτώνει το μοντέλο. Διαβάστε το πριν από την εγκατάσταση — μια δεξιότητα αποτελείται από οδηγίες που θα ακολουθήσει το μοντέλο σας.

Strategy Pattern (processor classes + a bulk loader)

A skill for dispatching on a string "type" value to one of several behaviors without an else if / switch chain. Each branch becomes a class; a loader auto-discovers the classes from a directory and picks one by a dispatch getter. The class skeleton each piece follows (one file / one class, static create() factory, JSDoc typedefs) comes from class-design — this skill covers how the three pieces fit together.

Reach for it when:

  • You would otherwise write if (type === 'a') ... else if (type === 'b') ....
  • New variants get added over time and you want to drop a file in a folder, not edit a switch.
  • Each branch has non-trivial logic worth testing in isolation.

Do not reach for it for a 2-branch boolean or a value map with no behavior — a plain lookup hash is enough there.

Grand principle: adding a variant means adding a file, never editing a dispatch chain

Every rule in this skill serves one point: the set of variants is discovered from the filesystem, not listed in code. A new variant is one new subclass file dropped into the processor directory; no existing file changes.

  • Why not a switch: an else if / switch chain concentrates every variant's wiring in one function, so every new variant edits (and risks breaking) shared code, and each branch's logic can't be tested in isolation. One-class-per-variant keeps each branch independently testable and reviewable.
  • Why auto-discovery: if the loader imported each subclass by name, the "chain" would just move into the import list. Loading every class in the directory (4) makes the directory itself the registry.
  • Why dispatch by getter: the key a processor handles is part of that processor's contract, so it lives on the subclass as an overridden getter — not in a name field passed from outside, and not in a mapping table kept next to the loader.
js
// Good: the caller asks the loader; variants stay out of the call site
const processor = loader.resolveProcessor(eventCategory)

if (!processor) {
  return null
}

return processor.process({
  event,
})
js
// Avoid: an else-if chain enumerating every variant at the call site
//   → every new variant edits this shared function; branches can't be tested in isolation
if (eventCategory === 'created') {
  return handleCreated(event)
} else if (eventCategory === 'updated') {
  return handleUpdated(event)
} else if (eventCategory === 'deleted') {
  return handleDeleted(event)
}

Comment language in the sample code

Comments in the js examples in this SKILL.md follow the prose language (here, English), because the examples are explanation of the skill. Comments inside the artifact this skill produces (the real processor / loader code) follow the codebase language — English — to match the surrounding source.

1. The three pieces

PieceRoleCount
Base classDeclares the static create() factory, the abstract dispatch getter (throws until overridden), and the abstract work method (throws until overridden)1
Concrete subclassesOne file per variant; each overrides the dispatch getter to return its key and overrides the work method1 per variant
Bulk loaderstatic async createAsync() loads every class in the processor directory via DeepBulkClassLoader, instantiates each; resolveProcessor(key) finds the one whose dispatch getter matches, ?? null1

Typical layout (a payment-gateway webhook example):

app/tools/eventProcessors/
├── BaseEventProcessor.js
├── concretes/
│   ├── CreateEventProcessor.js
│   ├── UpdateEventProcessor.js
│   └── DeleteEventProcessor.js
app/tools/bulkLoaders/
└── BulkEventProcessorsLoader.js

2. Base class: an abstract getter + an abstract work method

Dispatch is by getter, not by a processorName field or a static getName(). The getter throws until a subclass overrides it. static create() is the factory; the work method is abstract and also throws. Throwing abstract members are the whole "interface" — there is no TypeScript interface to implement.

js
/**
 * Base class for event processors.
 */
export default class BaseEventProcessor {
  /**
   * Factory method.
   *
   * @template {X extends typeof BaseEventProcessor ? X : never} T, X
   * @param {BaseEventProcessorFactoryParams} params - Parameters for the factory.
   * @returns {InstanceType<T>} An instance of the class.
   * @this {T}
   */
  static create (params) {
    return /** @type {InstanceType<T>} */ (
      new this(params)
    )
  }

  /**
   * get: Dispatch key this processor handles.
   *
   * @abstract
   * @returns {string}
   * @throws {Error} - When not overridden in a subclass.
   */
  get eventCategory () {
    throw new Error('eventCategory must be implemented in subclass')
  }

  /**
   * Process the event.
   *
   * @abstract
   * @param {EventProcessorParams} params - Parameters for processing.
   * @returns {Promise<*>}
   * @throws {Error} - When not overridden in a subclass.
   */
  async process ({
    event,
  }) {
    throw new Error('process must be implemented in subclass')
  }
}

/**
 * @typedef {object} EventProcessorParams
 * @property {*} event - The event to process.
 */

/**
 * @typedef {{
 *   [key: string]: *
 * }} BaseEventProcessorFactoryParams
 */
  • When a processor needs collaborators, take them as constructor deps and default them in create() (e.g. static create ({ randomTextGenerator = this.createRandomTextGenerator() } = {})), following class-design. Keep that shape rather than new-ing collaborators inside the work method.

3. Concrete subclass: one file per variant

Override the dispatch getter (mark it @override) to return the key from a shared constant hash, not a bare string literal, and override the work method. static create() is inherited from the base — subclasses only redefine it when they need extra defaults.

js
import BaseEventProcessor from '../BaseEventProcessor.js'

import CONSTANT from '../../../globals/constants.js'

const {
  EVENT_TYPE,
} = CONSTANT

/**
 * Event processor: handle "create" events.
 */
export default class CreateEventProcessor extends BaseEventProcessor {
  /**
   * get: Dispatch key this processor handles.
   *
   * @override
   * @returns {string}
   */
  get eventCategory () {
    return EVENT_TYPE.CREATE_RECORD
  }

  /**
   * Process the event.
   *
   * @override
   * @param {{
   *   event: *
   * }} params - Parameters for processing.
   * @returns {Promise<*>}
   */
  async process ({
    event,
  }) {
    return this.buildResult({
      event,
    })
  }
}
  • Why a constant hash for the key: the same key string appears on the producer side (the webhook / message payload) and the consumer side (the getter). A shared constant makes a typo a reference error instead of a silent dispatch miss.
  • Suffix concrete classes by role (~Processor, ~Handler, ~Converter), aligned with the base class name.

4. Bulk loader: auto-discover and pick by getter

The loader resolves the processor directory with rootPath.to(...), loads every class in it via DeepBulkClassLoader.create({ poolPath }).loadClasses(), and instantiates each with .create(). resolveProcessor(key) matches on the dispatch getter and returns ?? null on a miss — there is no default / fallback processor and no throw inside the loader.

js
import {
  DeepBulkClassLoader,
} from '@openreachtech/renchan'

import {
  rootPath,
} from '../../globals/_.js'

const eventProcessorPath = rootPath.to('app/tools/eventProcessors/concretes')

/**
 * Bulk loader for event processors.
 */
export default class BulkEventProcessorsLoader {
  /**
   * Constructor.
   *
   * @constructor
   * @param {BulkEventProcessorsLoaderConstructorParams} params - Parameters of this constructor.
   */
  constructor ({
    processors,
  }) {
    this.processors = processors
  }

  /**
   * Factory method as async.
   *
   * @param {string} [path] - The path to load processors from.
   * @returns {Promise<BulkEventProcessorsLoader>}
   */
  static async createAsync (path = eventProcessorPath) {
    const processorClasses = await this.loadProcessorClasses(path)

    const processors = processorClasses.map(ProcessorClass =>
      ProcessorClass.create()
    )

    return new this({
      processors,
    })
  }

  /**
   * Factory method.
   *
   * @template {X extends typeof BulkEventProcessorsLoader ? X : never} T, X
   * @param {BulkEventProcessorsLoaderFactoryParams} params - Parameters for the factory.
   * @returns {InstanceType<T>} An instance of the class.
   * @this {T}
   */
  static create (params) {
    return /** @type {InstanceType<T>} */ (
      new this(params)
    )
  }

  /**
   * Load processor classes from the specified path.
   *
   * @param {string} path - The path to load processor classes from.
   * @returns {Promise<Array<typeof import('../eventProcessors/BaseEventProcessor.js').default>>}
   */
  static async loadProcessorClasses (path) {
    return /** @type {*} */ (
      DeepBulkClassLoader.create({
        poolPath: path,
      })
        .loadClasses()
    )
  }

  /**
   * Resolve a processor by dispatch key.
   *
   * @param {string} eventCategory - The dispatch key.
   * @returns {import('../eventProcessors/BaseEventProcessor.js').default | null}
   */
  resolveProcessor (eventCategory) {
    return this.processors.find(processor => processor.eventCategory === eventCategory)
      ?? null
  }
}

/**
 * @typedef {object} BulkEventProcessorsLoaderConstructorParams
 * @property {Array<import('../eventProcessors/BaseEventProcessor.js').default>} processors - The event processors.
 */

/**
 * @typedef {{
 *   processors: Array<import('../eventProcessors/BaseEventProcessor.js').default>
 * }} BulkEventProcessorsLoaderFactoryParams
 */
  • Why ?? null and no fallback processor: what a miss means (skip? log? error response?) is the caller's decision, and it differs per call site. A 'default_processor' chain inside the loader hides unknown keys from the caller.
  • Build the loader once (at startup / in a shared instance) and reuse it — createAsync() reads the filesystem, so don't re-run it per event.

5. Caller side

The caller asks the loader for a processor and decides what a null means:

js
const loader = await BulkEventProcessorsLoader.createAsync()

const processor = loader.resolveProcessor(eventCategory)

if (!processor) {
  return null
}

return processor.process({
  event,
})

6. Testing

Following the hoc-jest skill, split files per class.

  • Base class: each abstract member throws (eventCategory, the work method); static create() returns an instance of the called class.
  • Each concrete subclass: inheritance (extends the base); the dispatch getter returns the expected constant; the work method's behavior with test.each() over its variable inputs.
  • Bulk loader: resolveProcessor() returns the matching processor for each known key (test.each() over the keys), and null for an unknown key — don't skip the miss case.

Finishing checklist

  • Did the change add a variant as one new subclass file, without editing a dispatch chain or an import list?
  • Is dispatch a getter overridden per subclass (no processorName field, no static getName())?
  • Do the abstract base members throw new Error('... must be implemented in subclass')?
  • Does the dispatch getter return its key from a shared constant hash, not a bare string literal?
  • Does the loader auto-discover via DeepBulkClassLoader from a rootPath.to(...) directory, and does resolveProcessor() return ?? null on a miss (no fallback processor, no throw)?
  • Is static create() the factory everywhere, with constructor deps defaulted in create() when needed (per class-design)?
  • One class per file, suffixed by role (~Processor, ~Handler, ~Converter)?
  • Do tests cover the abstract throws, each subclass's getter + behavior, and the loader's known-key / unknown-key cases?

Συχνές ερωτήσεις

Τι κάνει η δεξιότητα AI Hor Strategy Pattern;

Implement the strategy pattern as a trio of a base processor class, one concrete subclass per variant, and a bulk loader that auto-discovers the subclasses from a directory and picks one by a dispatch getter. Use this skill whenever the user asks to replace an else-if / switch chain that dispatches on a "type" string with pluggable processor classes, or to add a new event / webhook / message handler that must be auto-discovered.

Γιατί να χρησιμοποιήσετε τη δεξιότητα Hor Strategy Pattern στο TypingMind;

Επειδή την εγκαθιστάτε μία φορά και τη χρησιμοποιείτε με οποιοδήποτε μοντέλο. Η Hor Strategy Pattern είναι απλό Markdown και όχι κώδικας ειδικά για κάποιον πάροχο, επομένως η ίδια δεξιότητα λειτουργεί με GPT-5, Claude, Gemini, Grok ή ένα τοπικό μοντέλο — και μπορείτε να αλλάξετε μοντέλο κατά τη διάρκεια της συνομιλίας χωρίς να διακοπεί η λειτουργία της. Το TypingMind λειτουργεί με τα δικά σας κλειδιά API, οπότε πληρώνετε απευθείας τους παρόχους αντί για συνδρομή ανά θέση χρήστη, ενώ οι δεξιότητες και οι συνομιλίες σας παραμένουν στον δικό σας χώρο αποθήκευσης.

Πώς εγκαθιστώ τη Hor Strategy Pattern στο TypingMind;

Στο TypingMind, ανοίξτε Πρόσθετα → Δεξιότητες → Εγκατάσταση από το GitHub και επικολλήστε το https://github.com/openreachtech/hora-skills-ort-renchan/tree/main/kit/skills/hor-strategy-pattern. Το TypingMind διαβάζει το αρχείο SKILL.md και εγκαθιστά τη δεξιότητα, την οποία μπορείτε να ενεργοποιείτε ανά συνομιλία.

Ποια μοντέλα AI μπορούν να χρησιμοποιήσουν τη δεξιότητα Hor Strategy Pattern;

Οποιοδήποτε μοντέλο συνδέετε στο TypingMind. Οι δεξιότητες AI είναι απλές οδηγίες Markdown και όχι κώδικας ειδικά για κάποιον πάροχο, επομένως τα GPT, Claude, Gemini, Grok και τα τοπικά μοντέλα μπορούν όλα να φορτώσουν αυτή τη δεξιότητα όταν ένα αίτημα αντιστοιχεί σε αυτή.

Με πόσα μοντέλα AI μπορώ να χρησιμοποιήσω τη Hor Strategy Pattern;

Με όσα θέλετε. Εφόσον ένα μοντέλο υποστηρίζει δεξιότητες, μπορείτε να χρησιμοποιήσετε τη Hor Strategy Pattern με αυτό — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama και άλλα — όλα στο TypingMind με τα δικά σας κλειδιά API.

Είναι δωρεάν η δεξιότητα AI Hor Strategy Pattern;

Ναι. Δημοσιεύεται στο GitHub από τον χρήστη openreachtech με την άδεια χρήσης Apache-2.0. Πληρώνετε μόνο τον δικό σας πάροχο AI για τα token που χρησιμοποιείτε.

Τι είναι οι δεξιότητες AI;

Μια δεξιότητα AI είναι ένα επαναχρησιμοποιήσιμο πακέτο οδηγιών που διδάσκει σε ένα μοντέλο AI πώς να εκτελεί μια συγκεκριμένη εργασία. Ακολουθεί την ανοιχτή μορφή Agent Skills: ένα αρχείο SKILL.md με όνομα και περιγραφή, μαζί με τυχόν σενάρια κώδικα, πρότυπα ή αρχεία αναφοράς που μπορεί να χρειαστεί το μοντέλο. Το μοντέλο διαβάζει τις οδηγίες μόνο όταν το αίτημά σας αντιστοιχεί στη δεξιότητα, οπότε μια εγκατεστημένη δεξιότητα δεν κοστίζει τίποτα μέχρι να χρησιμοποιηθεί.

Σε τι διαφέρουν οι δεξιότητες AI από τα πρόσθετα ή τους συνδέσμους MCP;

Ένα πρόσθετο ή ένας σύνδεσμος MCP παρέχει στο μοντέλο νέα εργαλεία που μπορεί να καλέσει — κώδικα που εκτελείται κάπου και επιστρέφει ένα αποτέλεσμα. Μια δεξιότητα AI παρέχει αντί γι’ αυτό γνώσεις και διαδικασίες στο μοντέλο: πώς να προσεγγίσει μια εργασία, ποια βήματα να ακολουθήσει και ποια χαρακτηριστικά έχει ένα καλό αποτέλεσμα. Οι δεξιότητες είναι απλό Markdown, επομένως δεν χρειάζονται διακομιστή, κλειδί API ή περιβάλλον εκτέλεσης και λειτουργούν με οποιοδήποτε μοντέλο.

Προβολή όλων

Στήστε δικό σας χώρο εργασίας AI τώρα

Εγγραφείτε στο ενημερωτικό μας δελτίο για να ενημερώνεστε για νέες λειτουργίες και μελλοντικές κληρώσεις δώρων 👇