スキル一覧に戻る
saknarinZ

refactoring

by saknarinZ

agent_skills

0🍴 0📅 2026年1月19日
GitHubで見るManusで実行

SKILL.md


name: Refactoring description: ปรับปรุงโค้ดให้ดีขึ้นโดยไม่เปลี่ยน behavior

Refactoring Skill

Overview

Skill สำหรับปรับปรุงคุณภาพโค้ด ทำให้อ่านง่าย maintain ง่าย และมีประสิทธิภาพมากขึ้น

Refactoring Principles

SOLID Principles

  1. Single Responsibility - แต่ละ class/function ทำหน้าที่เดียว
  2. Open/Closed - เปิดสำหรับ extension, ปิดสำหรับ modification
  3. Liskov Substitution - Subclass ใช้แทน parent ได้
  4. Interface Segregation - Interface เล็กๆ เฉพาะทาง
  5. Dependency Inversion - Depend on abstractions, not concretions

Other Principles

  • DRY - Don't Repeat Yourself
  • KISS - Keep It Simple, Stupid
  • YAGNI - You Aren't Gonna Need It

Code Smells & Solutions

Bloaters

SmellSolution
Long MethodExtract Method - แยกเป็น functions เล็กๆ
Large ClassExtract Class - แยกเป็น classes
Long Parameter ListParameter Object - รวมเป็น object
Data ClumpsExtract Class - สร้าง class รวม data ที่ใช้ด้วยกัน

Object-Orientation Abusers

SmellSolution
Switch StatementsReplace with Polymorphism
Parallel InheritanceMerge hierarchies
Refused BequestReplace Inheritance with Delegation

Change Preventers

SmellSolution
Divergent ChangeExtract Class - แยก concerns
Shotgun SurgeryMove Method/Field - รวม related code

Dispensables

SmellSolution
Dead Codeลบทิ้ง
Duplicate CodeExtract Method/Class
Lazy ClassInline Class - รวมกับ class อื่น
Comments (excessive)Rename/Extract - ให้ code self-documenting

Couplers

SmellSolution
Feature EnvyMove Method - ย้ายไปที่ class ที่ใช้ data
Message ChainsHide Delegate - สร้าง wrapper method
Middle ManRemove Middle Man - เรียกตรง

Common Refactoring Techniques

Extract Method

// Before
function printUserInfo(user) {
  console.log("---USER INFO---");
  console.log(`Name: ${user.name}`);
  console.log(`Email: ${user.email}`);
  console.log(`Age: ${user.age}`);
  console.log("---------------");
}

// After
function printUserInfo(user) {
  printHeader();
  printDetails(user);
  printFooter();
}

function printHeader() {
  console.log("---USER INFO---");
}

function printDetails(user) {
  console.log(`Name: ${user.name}`);
  console.log(`Email: ${user.email}`);
  console.log(`Age: ${user.age}`);
}

function printFooter() {
  console.log("---------------");
}

Replace Conditional with Polymorphism

// Before
function calculateArea(shape: Shape): number {
  switch (shape.type) {
    case "circle":
      return Math.PI * shape.radius ** 2;
    case "rectangle":
      return shape.width * shape.height;
    case "triangle":
      return (shape.base * shape.height) / 2;
  }
}

// After
interface Shape {
  calculateArea(): number;
}

class Circle implements Shape {
  constructor(private radius: number) {}
  calculateArea(): number {
    return Math.PI * this.radius ** 2;
  }
}

class Rectangle implements Shape {
  constructor(
    private width: number,
    private height: number,
  ) {}
  calculateArea(): number {
    return this.width * this.height;
  }
}

Introduce Parameter Object

// Before
function createUser(name: string, email: string, age: number,
                    address: string, phone: string) { ... }

// After
interface UserData {
  name: string;
  email: string;
  age: number;
  address: string;
  phone: string;
}

function createUser(data: UserData) { ... }

Refactoring Process

  1. Ensure Tests Exist - มี tests ก่อน refactor
  2. Make Small Changes - เปลี่ยนทีละน้อย
  3. Run Tests Often - ทดสอบหลังทุกการเปลี่ยน
  4. Commit Frequently - commit ทีละ refactoring
  5. Review - ตรวจสอบผลลัพธ์

Refactoring Checklist

  • มี tests ครอบคลุมก่อน refactor
  • ระบุ code smells ที่ต้องการแก้
  • วางแผนการ refactor
  • ทำทีละ step เล็กๆ
  • Run tests หลังทุก step
  • Review ว่า code ดีขึ้นจริง
  • Update documentation ถ้าจำเป็น

スコア

総合スコア

45/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

0/5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です