本文へ移動
cccskills
無料GitHub で公開

acc-grasp-knowledge

GRASP principles knowledge base for PHP 8.5 projects. Provides quick reference for 9 responsibility assignment patterns (Information Expert, Creator, Controller, Low Coupling, High Cohesion, Polymorphism, Pure Fabrication, Indirection, Protected Variations). Use for architecture audits and design decisions.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md5.5 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

GRASP Principles Knowledge Base

Overview

GRASP (General Responsibility Assignment Software Patterns) provides guidelines for assigning responsibilities to classes and objects in object-oriented design.

PrincipleCore QuestionGoal
Information ExpertWho has the data?Assign to class with information
CreatorWho creates objects?Assign creation responsibility
ControllerWho handles system events?Coordinate use case flow
Low CouplingHow to reduce dependencies?Minimize interconnections
High CohesionHow to focus responsibilities?Keep related things together
PolymorphismHow to handle type variations?Use polymorphic operations
Pure FabricationWhat if no domain class fits?Create artificial class
IndirectionHow to decouple?Add intermediate object
Protected VariationsHow to handle change?Hide variation points

Quick Detection Patterns

Information Expert Violations

# Feature Envy: Class uses other class's data more
Grep: "->get.*->get.*->get" --glob "**/*.php"

# Train wreck calls
Grep: "->.*()->.*()->.*()->" --glob "**/*.php"

Signs: Method accesses other object's data extensively, data and behavior separated.

Creator Violations

# Random creation locations
Grep: "new\s\+[A-Z][a-z]*[A-Z]" --glob "**/*.php"

Signs: Objects created in unexpected places, no clear creation ownership.

Controller Violations

# Fat controllers (>100 lines)
find . -path "*/Controller/*.php" -exec wc -l {} \; | awk '$1 > 100'

# Business logic in controllers
Grep: "if.*&&.*||" --glob "*Controller.php"

Signs: Controller has >100 lines, business logic in controller.

Low Coupling Violations

# High dependency count (>7)
Grep: "__construct" --glob "**/*.php" -A 15

# Concrete type dependencies
Grep: "function.*([A-Z][a-z]*[A-Z]" --glob "**/*.php"

Signs: Class has >7 dependencies, depends on concrete classes.

High Cohesion Violations

# Unrelated method names
Grep: "public function" --glob "**/*.php" | grep -E "And[A-Z]|Or[A-Z]"

# Multiple responsibilities in class name
Grep: "class.*Manager|class.*Handler|class.*Processor" --glob "**/*.php"

Signs: Methods don't relate to each other, class does many unrelated things.

Quick PHP 8.5 Examples

Information Expert

// BAD: Logic outside of object with data
final class OrderService
{
    public function calculateTotal(Order $order): Money
    {
        $total = Money::zero();
        foreach ($order->getLines() as $line) {
            $total = $total->add($line->getProduct()->getPrice()->multiply($line->getQuantity()));
        }
        return $total;
    }
}

// GOOD: Logic in class that has the data
final class Order
{
    public function total(): Money
    {
        return array_reduce(
            $this->lines,
            fn(Money $sum, OrderLine $line) => $sum->add($line->total()),
            Money::zero(),
        );
    }
}

Low Coupling

// BAD: Depends on concrete classes
final class ReportGenerator
{
    public function __construct(
        private DoctrineOrderRepository $orders,
        private SymfonyMailer $mailer,
    ) {}
}

// GOOD: Depends on abstractions
final readonly class ReportGenerator
{
    public function __construct(
        private OrderReader $orders,
        private Mailer $mailer,
    ) {}
}

High Cohesion

// BAD: Low cohesion - unrelated responsibilities
final class UserManager
{
    public function register(array $data): User { }
    public function sendEmail(User $user): void { }
    public function generateReport(): string { }
}

// GOOD: High cohesion - focused responsibilities
final readonly class UserRegistrationService
{
    public function register(RegistrationData $data): User { }
    public function confirmEmail(Token $token): void { }
}

GRASP & DDD Integration

GRASPDDD Application
Information ExpertEntities contain their behavior
CreatorAggregates create their entities
ControllerApplication Services / Use Cases
Low CouplingBounded Context boundaries
High CohesionAggregate consistency boundary
PolymorphismDomain Services, Strategies
Pure FabricationRepositories, Factories, Specifications
IndirectionAnti-Corruption Layer, Adapters
Protected VariationsPorts & Adapters, Domain Events

References

For detailed patterns and examples, see references/:

  • information-expert.md — Tell Don't Ask, calculations in owner
  • creator.md — Factory patterns, aggregation rules
  • controller.md — Use case handlers, thin controllers
  • low-coupling.md — Dependency injection, abstractions
  • high-cohesion.md — Focused responsibilities
  • polymorphism.md — Strategy pattern, type variations
  • pure-fabrication.md — Repositories, specifications
  • indirection.md — Adapters, mediators
  • protected-variations.md — Stable interfaces
  • antipatterns.md — Common GRASP violations

Assets

  • assets/report-template.md — GRASP audit report format

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Master backend architectures, REST API design, microservices, and server-side development across multiple languages. Use this as a central index to access specialized sub-skills.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

在每次回复中使用固定前缀并列出本次实际参考的指令/文件,便于校验是否遵循上下文与规则。

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

Automate 21risk tasks via Rube MCP (Composio). Always search tools first for current schemas.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

Automate 2chat tasks via Rube MCP (Composio). Always search tools first for current schemas.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

Arquitecto de Soluciones Principal y Consultor Tecnológico de Andru.ia. Diagnostica y traza la hoja de ruta óptima para proyectos de IA en español.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

[00] META. Orchestrate skills into dynamic chains for complex tasks. Analyzes the task, discovers available skills, builds an optimal chain, explains why each skill is needed, and executes step-by-step with user confirmation. Use for any complex task requiring multiple thinking/research/analysis steps. Triggers on "plan this", "how to approach", "what's the strategy", "build a plan", or any multi-step problem requiring skill orchestration.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

MikeCheng1208 のスキルをすべて見る

このスキルの問題を報告する