Maintenance in progress: we are indexing a large batch of new skills. Some pages may load slowly or briefly show no results. Nothing is lost, and everything is back to normal within the hour.

Patterns/factory

Factory Pattern pattern for C development

majiayu000 6627645 2 files · 1.4 KB Updated 567 repo stars

File contents

Factory Pattern

Function that encapsulates object creation, returning an allocated and initialized struct. Centralizes construction logic and hides allocation details from callers.

ikigai Application

Current usage:

  • ik_scrollback_create() - creates scrollback buffer
  • ik_mark_create() - creates checkpoint marks
  • ik_input_parser_create() - creates input parser

Convention: Use *_create() for heap allocation (caller owns), *_init() for initializing pre-allocated memory.

With ik_env_t: Factories should receive ik_env_t *env as first parameter for access to logger, config, and clock during construction.

Testing: Factories enable injecting dependencies at creation time rather than reaching for globals.

majiayu000/claude-skill-registry-data/tree/main/data/factory commit 66276452c2

Frequently asked questions

npx skillmds add majiayu000/patterns-factory