MR
Mayur Rathi
@github
⭐ 34.1k GitHub stars

Object-Calisthenics

Object-Calisthenics是一款code方向的AI技能,核心价值是Enforces Object Calisthenics principles for business domain code to ensure clean, maintainable, and robust code,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。

Enforces Object Calisthenics principles for business domain code to ensure clean, maintainable, and robust code

Last verified on: 2026-05-30
mkdir -p ./skills/object-calisthenics && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/object-calisthenics/SKILL.md -o ./skills/object-calisthenics/SKILL.md

Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).

Skill Content

# Object Calisthenics Rules


> ⚠️ **Warning:** This file contains the 9 original Object Calisthenics rules. No additional rules must be added, and none of these rules should be replaced or removed.

> Examples may be added later if needed.


Objective

This rule enforces the principles of Object Calisthenics to ensure clean, maintainable, and robust code in the backend, **primarily for business domain code**.


Scope and Application

- **Primary focus**: Business domain classes (aggregates, entities, value objects, domain services)

- **Secondary focus**: Application layer services and use case handlers

- **Exemptions**:

- DTOs (Data Transfer Objects)

- API models/contracts

- Configuration classes

- Simple data containers without business logic

- Infrastructure code where flexibility is needed


Key Principles



1. **One Level of Indentation per Method**:

- Ensure methods are simple and do not exceed one level of indentation.


```csharp

// Bad Example - this method has multiple levels of indentation

public void SendNewsletter() {

foreach (var user in users) {

if (user.IsActive) {

// Do something

mailer.Send(user.Email);

}

}

}

// Good Example - Extracted method to reduce indentation

public void SendNewsletter() {

foreach (var user in users) {

SendEmail(user);

}

}

private void SendEmail(User user) {

if (user.IsActive) {

mailer.Send(user.Email);

}

}


// Good Example - Filtering users before sending emails

public void SendNewsletter() {

var activeUsers = users.Where(user => user.IsActive);


foreach (var user in activeUsers) {

mailer.Send(user.Email);

}

}

```

2. **Don't Use the ELSE Keyword**:


- Avoid using the `else` keyword to reduce complexity and improve readability.

- Use early returns to handle conditions instead.

- Use Fail Fast principle

- Use Guard Clauses to validate inputs and conditions at the beginning of methods.


```csharp

// Bad Example - Using else

public void ProcessOrder(Order order) {

if (order.IsValid) {

// Process order

} else {

// Handle invalid order

}

}

// Good Example - Avoiding else

public void ProcessOrder(Order order) {

if (!order.IsValid) return;

// Process order

}

```


Sample Fail fast principle:

```csharp

public void ProcessOrder(Order order) {

if (order == null) throw new ArgumentNullException(nameof(order));

if (!order.IsValid) throw new InvalidOperationException("Invalid order");

// Process order

}

```


3. **Wrapping All Primitives and Strings**:

- Avoid using primitive types directly in your code.

- Wrap them in classes to provide meaningful context and behavior.


```csharp

// Bad Example - Using primitive types directly

public class User {

public string Name { get; set; }

public int Age { get; set; }

}

// Good Example - Wrapping primitives

public class User {

private string name;

private Age age;

public User(string name, Age age) {

this.name = name;

this.age = age;

}

}

public class Age {

private int value;

public Age(int value) {

if (value < 0) throw new ArgumentOutOfRangeException(nameof(value), "Age cannot be negative");

this.value = value;

}

}

```


4. **First Class Collections**:

- Use collections to encapsulate data and behavior, rather than exposing raw data structures.

First Class Collections: a class that contains an array as an attribute should not contain any other attributes


csharp
   // Bad Example - Exposing raw collection
   public class Group {
      public int Id { get; private set; }
      public string Name { get; private set; }
      public List<User> Users { get; private set; }

      public in

🎯 Best For

  • Claude users
  • GitHub Copilot users
  • Software engineers
  • Development teams
  • Tech leads

💡 Use Cases

  • Code quality improvement
  • Best practice enforcement

📖 How to Use This Skill

  1. 1

    Install the Skill

    Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.

  2. 2

    Load into Your AI Assistant

    Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.

  3. 3

    Apply Object-Calisthenics to Your Work

    Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.

  4. 4

    Review and Refine

    Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.

❓ Frequently Asked Questions

Is Object-Calisthenics compatible with Cursor and VS Code?

Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.

Do I need specific dependencies for Object-Calisthenics?

Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.

How do I install Object-Calisthenics?

Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/object-calisthenics/SKILL.md, ready to use.

Can I customize this skill for my team?

Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.

⚠️ Common Mistakes to Avoid

Skipping validation

Always test AI-generated code changes, even for simple refactors.

Missing dependency updates

Check if the skill requires updated dependencies or new packages.

🔗 Related Skills