refactoring/organizing-data

Encapsulate primitive fields and replace magic numbers with symbolic constants in TypeScript.

Updated Mar 26, 2026
One-click install
npx skills add https://github.com/johnnystefan/test-saas-business --skill refactoring-organizing-data
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactoring/organizing-data
Source: https://github.com/johnnystefan/test-saas-business/tree/main/skills/refactoring/organizing-data
Command: npx skills add https://github.com/johnnystefan/test-saas-business --skill refactoring-organizing-data

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill tackles primitive obsession and exposed mutable state by guiding you through encapsulating fields and collections, swapping magic numbers for symbolic constants, and modeling type codes with dedicated objects so your data structures become clearer and safer.

Core Features & Use Cases

  • Encapsulate Fields, Collections, and Access: Move public data into private members with getters, setters, and controlled collection modifiers to prevent external mutation.
  • Replace Primitives with Domain Objects: Promote strings, numbers, or arrays that carry behavior into meaningful classes that can validate, format, or enrich their contents.
  • Manage Type Codes and Identities: Turn raw type codes into classes or polymorphic hierarchies and centralize shared reference instances to avoid duplication.
  • Use Case: Refactor a customer order aggregate where primitive IDs, collections, and status codes are leaking through services, replacing them with value objects and read-only lists for safer semantics.

Quick Start

Ask the agent to refactor a class with primitive fields by encapsulating collections and replacing magic numbers with symbolic constants.

Frequently Asked Questions about refactoring/organizing-data

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix primitive obsession in TypeScript domain models?

To fix primitive obsession in TypeScript domain models, you encapsulate public fields into private members with controlled accessors and replace raw primitives with dedicated value objects that validate and enrich data.

What is the best way to encapsulate mutable collections in domain classes?

Encapsulating mutable collections in domain classes involves moving exposed arrays into private members and exposing read-only lists or controlled modifier methods to prevent external mutation and ensure safer data semantics.

How do I replace magic numbers with symbolic constants during refactoring?

Replacing magic numbers with symbolic constants during refactoring involves defining dedicated meaningful constants for numeric values in business logic, centralizing shared reference instances to avoid duplication and clarify intent.

When do I need to replace type codes with polymorphic classes?

You need to replace type codes with polymorphic classes when raw numeric or string codes carry behavior, turning them into dedicated class hierarchies to improve domain model clarity and resilience.

Can I use this refactoring approach on existing aggregates with exposed primitive IDs?

Yes, you can refactor existing aggregates with exposed primitive IDs by promoting those strings or numbers into meaningful value objects, providing safer semantics and validation for your business logic.