brycewang-stanford/Auto-Empirical-Research-Skills / skills/33-Galaxy-Dawn-claude-scholar/skills/architecture-design
architecture-design
VerifiedUse only when creating new registrable ML components that require Factory or Registry patterns.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 9.0 KB |
| examples/augmentation_example.py | script | 3.1 KB |
| examples/config_example.yaml | config | 2.3 KB |
| examples/custom_dataset.py | script | 1.5 KB |
| examples/custom_model.py | script | 6.1 KB |
| examples/pipeline_example.shexecutable | script | 5.0 KB |
| references/auto_import.md | markdown | 3.4 KB |
| references/code_style.md | markdown | 5.2 KB |
| references/factory_pattern.md | markdown | 1.4 KB |
| references/registry_pattern.md | markdown | 2.5 KB |
| references/structure.md | markdown | 4.8 KB |
references/factory_pattern.md
View on GitHub# Factory Pattern
## Overview
The Factory pattern allows dynamic creation of instances without specifying the exact class. Each module uses a factory to decouple creation from usage.
## Structure
```python
# In module __init__.py (e.g., data_module/dataset/__init__.py)
DATASET_FACTORY: Dict[str, type] = {}
def DatasetFactory(data_name: str):
"""Create dataset instance by name."""
dataset = DATASET_FACTORY.get(data_name, None)
if dataset is None:
# Fallback to default
dataset = DATASET_FACTORY.get('simple')
return dataset
```
## Usage
```python
# Consumer code doesn't need to know concrete class
dataset = DatasetFactory(cfg.dataset.name)
```
## Benefits
- **Loose coupling**: Consumer doesn't import concrete classes
- **Extensibility**: Add new types without changing consumer code
- **Fallback handling**: Graceful degradation for unknown types
- **Centralized registry**: Single source of truth for available types
## Implementation Details
1. Define factory dict at module level
2. Factory function handles lookup and fallback
3. Return class (not instance) for deferred initialization
4. None result triggers fallback to default implementation
## Common Patterns
```python
# With config integration
def DatasetFactory(cfg):
data_name = cfg.dataset.name
dataset_cls = DATASET_FACTORY.get(data_name)
if dataset_cls is None:
raise ValueError(f"Unknown dataset: {data_name}")
return dataset_cls(cfg)
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |