@booklib/skills 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +105 -0
- package/animation-at-work/SKILL.md +246 -0
- package/animation-at-work/assets/example_asset.txt +1 -0
- package/animation-at-work/references/api_reference.md +369 -0
- package/animation-at-work/references/review-checklist.md +79 -0
- package/animation-at-work/scripts/example.py +1 -0
- package/bin/skills.js +85 -0
- package/clean-code-reviewer/SKILL.md +292 -0
- package/clean-code-reviewer/evals/evals.json +67 -0
- package/data-intensive-patterns/SKILL.md +204 -0
- package/data-intensive-patterns/assets/example_asset.txt +1 -0
- package/data-intensive-patterns/references/api_reference.md +34 -0
- package/data-intensive-patterns/references/patterns-catalog.md +551 -0
- package/data-intensive-patterns/references/review-checklist.md +193 -0
- package/data-intensive-patterns/scripts/example.py +1 -0
- package/data-pipelines/SKILL.md +252 -0
- package/data-pipelines/assets/example_asset.txt +1 -0
- package/data-pipelines/references/api_reference.md +301 -0
- package/data-pipelines/references/review-checklist.md +181 -0
- package/data-pipelines/scripts/example.py +1 -0
- package/design-patterns/SKILL.md +245 -0
- package/design-patterns/assets/example_asset.txt +1 -0
- package/design-patterns/references/api_reference.md +1 -0
- package/design-patterns/references/patterns-catalog.md +726 -0
- package/design-patterns/references/review-checklist.md +173 -0
- package/design-patterns/scripts/example.py +1 -0
- package/domain-driven-design/SKILL.md +221 -0
- package/domain-driven-design/assets/example_asset.txt +1 -0
- package/domain-driven-design/references/api_reference.md +1 -0
- package/domain-driven-design/references/patterns-catalog.md +545 -0
- package/domain-driven-design/references/review-checklist.md +158 -0
- package/domain-driven-design/scripts/example.py +1 -0
- package/effective-java/SKILL.md +195 -0
- package/effective-java/assets/example_asset.txt +1 -0
- package/effective-java/references/api_reference.md +1 -0
- package/effective-java/references/items-catalog.md +955 -0
- package/effective-java/references/review-checklist.md +216 -0
- package/effective-java/scripts/example.py +1 -0
- package/effective-kotlin/SKILL.md +225 -0
- package/effective-kotlin/assets/example_asset.txt +1 -0
- package/effective-kotlin/references/api_reference.md +1 -0
- package/effective-kotlin/references/practices-catalog.md +1228 -0
- package/effective-kotlin/references/review-checklist.md +126 -0
- package/effective-kotlin/scripts/example.py +1 -0
- package/kotlin-in-action/SKILL.md +251 -0
- package/kotlin-in-action/assets/example_asset.txt +1 -0
- package/kotlin-in-action/references/api_reference.md +1 -0
- package/kotlin-in-action/references/practices-catalog.md +436 -0
- package/kotlin-in-action/references/review-checklist.md +204 -0
- package/kotlin-in-action/scripts/example.py +1 -0
- package/lean-startup/SKILL.md +250 -0
- package/lean-startup/assets/example_asset.txt +1 -0
- package/lean-startup/references/api_reference.md +319 -0
- package/lean-startup/references/review-checklist.md +137 -0
- package/lean-startup/scripts/example.py +1 -0
- package/microservices-patterns/SKILL.md +179 -0
- package/microservices-patterns/references/patterns-catalog.md +391 -0
- package/microservices-patterns/references/review-checklist.md +169 -0
- package/package.json +17 -0
- package/refactoring-ui/SKILL.md +236 -0
- package/refactoring-ui/assets/example_asset.txt +1 -0
- package/refactoring-ui/references/api_reference.md +355 -0
- package/refactoring-ui/references/review-checklist.md +114 -0
- package/refactoring-ui/scripts/example.py +1 -0
- package/storytelling-with-data/SKILL.md +238 -0
- package/storytelling-with-data/assets/example_asset.txt +1 -0
- package/storytelling-with-data/references/api_reference.md +379 -0
- package/storytelling-with-data/references/review-checklist.md +111 -0
- package/storytelling-with-data/scripts/example.py +1 -0
- package/system-design-interview/SKILL.md +213 -0
- package/system-design-interview/assets/example_asset.txt +1 -0
- package/system-design-interview/references/api_reference.md +582 -0
- package/system-design-interview/references/review-checklist.md +201 -0
- package/system-design-interview/scripts/example.py +1 -0
- package/using-asyncio-python/SKILL.md +242 -0
- package/using-asyncio-python/assets/example_asset.txt +1 -0
- package/using-asyncio-python/references/api_reference.md +267 -0
- package/using-asyncio-python/references/review-checklist.md +149 -0
- package/using-asyncio-python/scripts/example.py +1 -0
- package/web-scraping-python/SKILL.md +259 -0
- package/web-scraping-python/assets/example_asset.txt +1 -0
- package/web-scraping-python/references/api_reference.md +393 -0
- package/web-scraping-python/references/review-checklist.md +163 -0
- package/web-scraping-python/scripts/example.py +1 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Domain-Driven Design — Code Review Checklist
|
|
2
|
+
|
|
3
|
+
Systematic checklist for reviewing code against DDD principles. Organized by
|
|
4
|
+
category with specific items to inspect.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. Ubiquitous Language
|
|
9
|
+
|
|
10
|
+
- [ ] **Class names match domain terms** — Classes are named after domain concepts the business recognizes, not technical abstractions (e.g., `Policy` not `RuleEngine`, `Shipment` not `DataTransferObject`)
|
|
11
|
+
- [ ] **Method names describe domain operations** — Methods read like domain actions (e.g., `order.cancel()` not `order.setStatus(CANCELLED)`, `account.debit(amount)` not `account.updateBalance(-amount)`)
|
|
12
|
+
- [ ] **No technical jargon in domain layer** — Avoid names like Manager, Handler, Processor, Helper, Util, Data, Info in the domain layer
|
|
13
|
+
- [ ] **Consistent vocabulary** — Same concept uses the same name everywhere. No synonyms (e.g., don't mix "client" and "customer" for the same concept)
|
|
14
|
+
- [ ] **Language reflects current understanding** — Terms have been refined as the model evolved, not stuck with initial naive names
|
|
15
|
+
- [ ] **Module/package names tell a domain story** — Packages are organized by domain concept, not by pattern type (not `entities/`, `services/`, `repositories/`)
|
|
16
|
+
|
|
17
|
+
## 2. Layered Architecture
|
|
18
|
+
|
|
19
|
+
- [ ] **Four layers identifiable** — UI/Presentation, Application, Domain, Infrastructure are clearly separated
|
|
20
|
+
- [ ] **Domain layer has zero outward dependencies** — Domain classes don't import UI, Application, or Infrastructure classes
|
|
21
|
+
- [ ] **Infrastructure implements domain interfaces** — Dependency Inversion: domain defines interfaces (e.g., `OrderRepository`), infrastructure implements them (e.g., `JpaOrderRepository`)
|
|
22
|
+
- [ ] **Application layer is thin** — Application services coordinate but contain NO business logic. They manage transactions, security, and use-case flow
|
|
23
|
+
- [ ] **No domain logic in controllers** — UI/API controllers delegate to application services, never contain business rules
|
|
24
|
+
- [ ] **No domain logic in infrastructure** — Persistence logic doesn't enforce business rules; it only stores and retrieves
|
|
25
|
+
- [ ] **No circular dependencies** — Lower layers never depend on higher layers
|
|
26
|
+
|
|
27
|
+
## 3. Entities
|
|
28
|
+
|
|
29
|
+
- [ ] **Identity is explicit** — Entity has a clear, typed identifier (preferably a Value Object like `OrderId`, not a raw `String` or `long`)
|
|
30
|
+
- [ ] **Equality based on identity** — `equals()` and `hashCode()` use the identifier, not attributes
|
|
31
|
+
- [ ] **Encapsulates behavior** — Entity contains domain logic, not just getters and setters
|
|
32
|
+
- [ ] **Lifecycle management** — Entity handles its own state transitions and lifecycle events
|
|
33
|
+
- [ ] **Not overloaded** — Entity is focused on identity and core behavior; ancillary logic is in Value Objects or Services
|
|
34
|
+
- [ ] **Attributes that change are still same entity** — Design acknowledges that attributes can change while identity persists
|
|
35
|
+
|
|
36
|
+
## 4. Value Objects
|
|
37
|
+
|
|
38
|
+
- [ ] **Immutable** — No setters, no mutable state. All fields are final/readonly
|
|
39
|
+
- [ ] **Equality by attributes** — `equals()` compares all attributes, not reference identity
|
|
40
|
+
- [ ] **Rich behavior** — Value Objects contain domain logic (calculations, validations, transformations), not just data
|
|
41
|
+
- [ ] **Side-effect-free methods** — Operations return new Value Objects rather than modifying state
|
|
42
|
+
- [ ] **Used instead of primitives** — Domain concepts like money, dates, addresses, quantities are Value Objects, not raw types (no `double price`, `String email`, `int quantity`)
|
|
43
|
+
- [ ] **Freely shareable** — No aliasing bugs because they're immutable
|
|
44
|
+
- [ ] **Self-validating** — Value Object constructor validates invariants (e.g., `Email` rejects invalid format)
|
|
45
|
+
|
|
46
|
+
## 5. Aggregates
|
|
47
|
+
|
|
48
|
+
- [ ] **Clear root entity** — One Entity is the root with global identity; all access goes through it
|
|
49
|
+
- [ ] **Boundary is defined** — It's clear which Entities and Value Objects are inside the Aggregate
|
|
50
|
+
- [ ] **Invariants enforced by root** — The root ensures all business rules within the boundary are consistent
|
|
51
|
+
- [ ] **No external references to internals** — Outside code cannot hold direct references to internal entities. References are through the root only
|
|
52
|
+
- [ ] **Kept small** — Aggregate contains only what's needed for invariant enforcement. Other Aggregates are referenced by ID
|
|
53
|
+
- [ ] **One Aggregate per transaction** — Changes to one Aggregate are committed in one transaction. Cross-Aggregate changes are eventually consistent
|
|
54
|
+
- [ ] **Delete cascades from root** — Removing the root removes everything inside the boundary
|
|
55
|
+
- [ ] **Internal entities have local identity** — IDs of internal entities are meaningful only within the Aggregate
|
|
56
|
+
|
|
57
|
+
## 6. Repositories
|
|
58
|
+
|
|
59
|
+
- [ ] **Only for Aggregate roots** — No Repository exists for internal Aggregate entities or Value Objects
|
|
60
|
+
- [ ] **Collection-like interface** — API resembles an in-memory collection: add, remove, find, query
|
|
61
|
+
- [ ] **Interface in domain layer** — The Repository interface is defined in the domain layer
|
|
62
|
+
- [ ] **Implementation in infrastructure** — The concrete class (JPA, JDBC, etc.) is in the infrastructure layer
|
|
63
|
+
- [ ] **Returns whole Aggregates** — Queries return fully reconstituted Aggregates, not partial objects or DTOs
|
|
64
|
+
- [ ] **No persistence leakage** — Domain code has no awareness of SQL, ORM annotations, or storage details
|
|
65
|
+
- [ ] **Encapsulates query strategy** — Complex queries are behind well-named methods, not scattered SQL
|
|
66
|
+
- [ ] **Delegates to Factory for reconstitution** — Complex object rebuilding is handled by a Factory, not in the Repository itself
|
|
67
|
+
|
|
68
|
+
## 7. Factories
|
|
69
|
+
|
|
70
|
+
- [ ] **Used for complex creation** — If creation requires more than a simple constructor, a Factory exists
|
|
71
|
+
- [ ] **Atomic creation** — Factory produces a valid, consistent object or fails entirely (no partially created objects)
|
|
72
|
+
- [ ] **Invariants enforced at creation** — All Aggregate invariants are validated during Factory creation
|
|
73
|
+
- [ ] **Abstracts concrete types** — Client code depends on abstractions, not on the specific class the Factory creates
|
|
74
|
+
- [ ] **Reconstitution vs. creation distinguished** — Factories for loading from persistence don't re-validate business rules that only apply at creation time, and don't generate new IDs
|
|
75
|
+
|
|
76
|
+
## 8. Domain Services
|
|
77
|
+
|
|
78
|
+
- [ ] **Stateless** — Domain Services hold no mutable state between calls
|
|
79
|
+
- [ ] **Named in Ubiquitous Language** — Service name describes a domain operation (e.g., `TransferService`, `PricingService`)
|
|
80
|
+
- [ ] **Not overused** — Domain Services are the exception, not the rule. Most behavior belongs on Entities and Value Objects
|
|
81
|
+
- [ ] **Parameters and return types are domain objects** — Service interfaces use domain types, not primitives or infrastructure types
|
|
82
|
+
- [ ] **No anemic domain model** — If all logic is in Services and Entities are just data bags, the model is anemic
|
|
83
|
+
- [ ] **Distinguished from Application Services** — Domain Services contain business logic; Application Services coordinate use cases
|
|
84
|
+
|
|
85
|
+
## 9. Supple Design
|
|
86
|
+
|
|
87
|
+
- [ ] **Intention-Revealing Interfaces** — Can a developer understand what a class/method does without reading the implementation?
|
|
88
|
+
- [ ] **Side-Effect-Free Functions** — Complex logic lives in pure functions (especially on Value Objects). Commands are simple state changes
|
|
89
|
+
- [ ] **Assertions / Post-conditions** — Critical invariants are documented or enforced. Tests verify post-conditions
|
|
90
|
+
- [ ] **Conceptual Contours** — Object boundaries align with natural domain concepts. Things that change together are together
|
|
91
|
+
- [ ] **Standalone Classes** — Dependencies are minimized. Each class can be understood with minimal context
|
|
92
|
+
- [ ] **Closure of Operations** — Operations on a type return the same type where natural (e.g., `Money.add(Money): Money`)
|
|
93
|
+
- [ ] **Declarative style** — Where possible, the code describes WHAT should happen, not HOW (e.g., specifications, rules)
|
|
94
|
+
|
|
95
|
+
## 10. Specification Pattern
|
|
96
|
+
|
|
97
|
+
- [ ] **Business rules as objects** — Complex boolean conditions are modeled as Specification objects, not inline conditionals
|
|
98
|
+
- [ ] **isSatisfiedBy method** — Each Specification has a clear test method
|
|
99
|
+
- [ ] **Composable** — Specifications can be combined with AND, OR, NOT
|
|
100
|
+
- [ ] **Three use cases considered** — Validation (testing), Selection (querying), Building-to-order (generation)
|
|
101
|
+
- [ ] **Named in domain language** — `OverdueInvoiceSpecification`, not `InvoiceFilter42`
|
|
102
|
+
- [ ] **Implemented as Value Objects** — Specifications are immutable and side-effect-free
|
|
103
|
+
|
|
104
|
+
## 11. Strategic Design — Bounded Contexts
|
|
105
|
+
|
|
106
|
+
- [ ] **Contexts are explicitly defined** — Each Bounded Context has a clear name and boundary
|
|
107
|
+
- [ ] **One model per context** — No concept is defined differently within the same context
|
|
108
|
+
- [ ] **Context Map exists** — Relationships between contexts are documented
|
|
109
|
+
- [ ] **Integration patterns identified** — Each context-to-context relationship uses a named pattern (Shared Kernel, ACL, Conformist, etc.)
|
|
110
|
+
- [ ] **No model bleeding** — Types from one context don't appear in another context's domain layer
|
|
111
|
+
- [ ] **Team boundaries align** — Ideally, one team per Bounded Context
|
|
112
|
+
|
|
113
|
+
## 12. Integration Patterns
|
|
114
|
+
|
|
115
|
+
- [ ] **Anticorruption Layer present where needed** — External systems and legacy integrations are wrapped in ACL
|
|
116
|
+
- [ ] **ACL components identifiable** — Façade, Adapter, and Translator are present as needed
|
|
117
|
+
- [ ] **Domain interfaces define integration** — The domain layer defines what it needs; infrastructure implements it
|
|
118
|
+
- [ ] **Shared Kernel is minimal** — If two contexts share code, the shared portion is as small as possible with joint CI
|
|
119
|
+
- [ ] **Open Host Service is well-documented** — Public APIs have clear protocols and versioning
|
|
120
|
+
- [ ] **Published Language is formal** — Shared data formats are documented and standardized
|
|
121
|
+
- [ ] **Conformist choice is conscious** — If a team conforms to an upstream model, it's a deliberate decision with documented trade-offs
|
|
122
|
+
|
|
123
|
+
## 13. Distillation
|
|
124
|
+
|
|
125
|
+
- [ ] **Core Domain identified** — The team knows which part of the system is the competitive differentiator
|
|
126
|
+
- [ ] **Best talent on Core** — The most skilled developers are working on the Core Domain
|
|
127
|
+
- [ ] **Generic Subdomains simplified** — Non-core parts use off-the-shelf solutions, simpler models, or outsourced implementations
|
|
128
|
+
- [ ] **Domain Vision Statement exists** — A short document describes the Core Domain's value proposition
|
|
129
|
+
- [ ] **Core is highlighted** — Developers can quickly identify which code is Core Domain (via packages, annotations, or documentation)
|
|
130
|
+
- [ ] **Segregated Core** — Core Domain code is in its own module with minimal dependencies on supporting code
|
|
131
|
+
|
|
132
|
+
## 14. Large-Scale Structure
|
|
133
|
+
|
|
134
|
+
- [ ] **Structure serves the team** — If a large-scale structure exists, it helps developers navigate and make decisions
|
|
135
|
+
- [ ] **Not over-engineered** — Structure is as simple as possible. No structure is better than bad structure
|
|
136
|
+
- [ ] **Evolving** — Structure is allowed to change as understanding deepens
|
|
137
|
+
- [ ] **Responsibility Layers (if used)** — Layers have clear domain-level responsibilities and dependencies flow downward
|
|
138
|
+
- [ ] **Knowledge Level (if used)** — Configuration rules are separated from operational data in a meta-model
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Quick Review Workflow
|
|
143
|
+
|
|
144
|
+
1. **Start with Ubiquitous Language** — Read the code. Does it speak the domain? Can a domain expert recognize the concepts?
|
|
145
|
+
2. **Check architecture** — Are layers separated? Does the domain depend on nothing?
|
|
146
|
+
3. **Inspect building blocks** — Are Entities, Value Objects, Aggregates, Repositories, and Services used correctly?
|
|
147
|
+
4. **Evaluate design quality** — Is the design supple? Intention-revealing? Side-effect-free where possible?
|
|
148
|
+
5. **Assess strategic alignment** — Are Bounded Contexts defined? Is the Core Domain getting the most attention?
|
|
149
|
+
6. **Flag anti-patterns** — Look for anemic domain model, God Aggregates, primitive obsession, leaking infrastructure, missing ACL
|
|
150
|
+
|
|
151
|
+
## Severity Levels
|
|
152
|
+
|
|
153
|
+
| Severity | Description | Example |
|
|
154
|
+
|----------|------------|---------|
|
|
155
|
+
| **Critical** | Broken invariants, data corruption risk, no domain model | Anemic domain model, no Aggregate boundaries, infrastructure in domain |
|
|
156
|
+
| **High** | Incorrect pattern application, model integrity issues | Repository for non-root, mutable Value Objects, leaked internals |
|
|
157
|
+
| **Medium** | Design improvement opportunities | Missing Specifications, primitive types for concepts, overly large Aggregates |
|
|
158
|
+
| **Low** | Polish and naming refinements | Inconsistent naming, missing documentation, suboptimal module organization |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: effective-java
|
|
3
|
+
description: >
|
|
4
|
+
Generate and review Java code using patterns and best practices from Joshua Bloch's
|
|
5
|
+
"Effective Java" (3rd Edition). Use this skill whenever the user asks about Java best
|
|
6
|
+
practices, API design, object creation patterns, generics, enums, lambdas, streams,
|
|
7
|
+
concurrency, serialization, method design, exception handling, or writing clean,
|
|
8
|
+
maintainable Java code. Trigger on phrases like "Effective Java", "Java best practices",
|
|
9
|
+
"builder pattern", "static factory", "defensive copy", "immutable class", "enum type",
|
|
10
|
+
"generics", "bounded wildcard", "PECS", "stream pipeline", "optional", "thread safety",
|
|
11
|
+
"serialization proxy", "checked exception", "try-with-resources", "composition over
|
|
12
|
+
inheritance", "method reference", "functional interface", or "Java API design."
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
# Effective Java Skill
|
|
16
|
+
|
|
17
|
+
You are an expert Java architect grounded in the 90 items from Joshua Bloch's
|
|
18
|
+
*Effective Java* (3rd Edition). You help developers in two modes:
|
|
19
|
+
|
|
20
|
+
1. **Code Generation** — Produce well-structured Java code following Effective Java principles
|
|
21
|
+
2. **Code Review** — Analyze existing Java code and recommend improvements
|
|
22
|
+
|
|
23
|
+
## How to Decide Which Mode
|
|
24
|
+
|
|
25
|
+
- If the user asks you to *build*, *create*, *generate*, *implement*, or *scaffold* something → **Code Generation**
|
|
26
|
+
- If the user asks you to *review*, *check*, *improve*, *audit*, or *critique* code → **Code Review**
|
|
27
|
+
- If ambiguous, ask briefly which mode they'd prefer
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Mode 1: Code Generation
|
|
32
|
+
|
|
33
|
+
When generating Java code, follow this decision flow:
|
|
34
|
+
|
|
35
|
+
### Step 1 — Understand the Requirements
|
|
36
|
+
|
|
37
|
+
Ask (or infer from context) what the component needs:
|
|
38
|
+
|
|
39
|
+
- **Object creation** — How should instances be created? (Factory, Builder, Singleton, DI)
|
|
40
|
+
- **Mutability** — Does the class need to be mutable or can it be immutable?
|
|
41
|
+
- **Inheritance model** — Composition, interface-based, or class hierarchy?
|
|
42
|
+
- **Concurrency** — Will this be accessed from multiple threads?
|
|
43
|
+
- **API surface** — Is this internal or part of a public API?
|
|
44
|
+
|
|
45
|
+
### Step 2 — Select the Right Patterns
|
|
46
|
+
|
|
47
|
+
Read `references/items-catalog.md` for full item details. Quick decision guide:
|
|
48
|
+
|
|
49
|
+
| Problem | Items to Apply |
|
|
50
|
+
|---------|---------------|
|
|
51
|
+
| How to create objects? | Item 1 (static factories), Item 2 (Builder), Item 3 (Singleton), Item 5 (DI) |
|
|
52
|
+
| How to design an immutable class? | Item 17 (minimize mutability), Item 50 (defensive copies) |
|
|
53
|
+
| How to model types? | Item 20 (interfaces over abstract classes), Item 23 (class hierarchies over tagged classes) |
|
|
54
|
+
| How to use generics safely? | Item 26 (no raw types), Item 31 (bounded wildcards / PECS), Item 28 (lists over arrays) |
|
|
55
|
+
| How to use enums effectively? | Item 34 (enums over int constants), Item 37 (EnumSet), Item 38 (EnumMap) |
|
|
56
|
+
| How to use lambdas and streams? | Item 42 (lambdas over anon classes), Item 43 (method refs), Item 45 (streams judiciously) |
|
|
57
|
+
| How to design methods? | Item 49 (validate params), Item 50 (defensive copies), Item 51 (design signatures carefully) |
|
|
58
|
+
| How to handle errors? | Item 69 (exceptions for exceptional conditions), Item 71 (avoid unnecessary checked), Item 73 (translate exceptions) |
|
|
59
|
+
| How to handle concurrency? | Item 78 (synchronize shared mutable data), Item 79 (avoid excessive sync), Item 81 (concurrency utilities) |
|
|
60
|
+
| How to handle serialization? | Item 85 (prefer alternatives), Item 90 (serialization proxies) |
|
|
61
|
+
|
|
62
|
+
### Step 3 — Generate the Code
|
|
63
|
+
|
|
64
|
+
Follow these principles when writing Java code:
|
|
65
|
+
|
|
66
|
+
- **Static factories over constructors** — Use `of`, `from`, `valueOf`, `create` naming. Return interface types. Cache instances when possible (Item 1)
|
|
67
|
+
- **Builder for many parameters** — Any constructor with more than 3-4 parameters should use the Builder pattern with fluent API (Item 2)
|
|
68
|
+
- **Immutable by default** — Make fields `final`, make classes `final`, no setters, defensive copies in constructors and accessors (Item 17)
|
|
69
|
+
- **Composition over inheritance** — Wrap existing classes with forwarding methods instead of extending them. Use the decorator pattern (Item 18)
|
|
70
|
+
- **Program to interfaces** — Declare variables, parameters, and return types as interfaces, not concrete classes (Item 64)
|
|
71
|
+
- **Generics everywhere** — No raw types. Use `<? extends T>` for producers, `<? super T>` for consumers (PECS). Prefer `List<E>` over `E[]` (Items 26, 28, 31)
|
|
72
|
+
- **Enums over constants** — Never `public static final int`. Use enums with behavior, strategy enum pattern, and EnumSet/EnumMap (Items 34, 36, 37)
|
|
73
|
+
- **Lambdas and method references** — Prefer lambdas to anonymous classes, method references to lambdas when clearer. Use standard functional interfaces (Items 42-44)
|
|
74
|
+
- **Streams judiciously** — Don't overuse. Keep side-effect-free. Return `Collection` over `Stream` from APIs. Be careful with parallel streams (Items 45-48)
|
|
75
|
+
- **Defensive programming** — Validate parameters with `Objects.requireNonNull`, use `@Nullable` annotations, return empty collections not null, use Optional for return types (Items 49, 54, 55)
|
|
76
|
+
- **Exceptions done right** — Use unchecked for programming errors, checked for recoverable conditions. Translate exceptions at abstraction boundaries. Include failure-capture info (Items 69-77)
|
|
77
|
+
- **Thread safety by design** — Document thread safety levels. Prefer concurrency utilities (`ConcurrentHashMap`, `CountDownLatch`) over `wait`/`notify`. Use lazy initialization only when needed (Items 78-84)
|
|
78
|
+
- **Avoid Java serialization** — Use JSON, protobuf, or other formats. If you must use Serializable, use serialization proxies (Items 85-90)
|
|
79
|
+
|
|
80
|
+
When generating code, produce:
|
|
81
|
+
|
|
82
|
+
1. **Class design** — Access levels, mutability, type hierarchy
|
|
83
|
+
2. **Object creation** — Factory methods, builders, dependency injection
|
|
84
|
+
3. **API methods** — Parameter validation, return types, documentation
|
|
85
|
+
4. **Error handling** — Exception hierarchy, translation, failure atomicity
|
|
86
|
+
5. **Concurrency model** — Thread safety annotations, synchronization strategy
|
|
87
|
+
|
|
88
|
+
### Code Generation Examples
|
|
89
|
+
|
|
90
|
+
**Example 1 — Immutable Value Class with Builder:**
|
|
91
|
+
```
|
|
92
|
+
User: "Create a class to represent a nutritional facts label"
|
|
93
|
+
|
|
94
|
+
You should generate:
|
|
95
|
+
- Immutable class with private final fields (Item 17)
|
|
96
|
+
- Builder pattern with fluent API for optional params (Item 2)
|
|
97
|
+
- Static factory method NutritionFacts.builder() (Item 1)
|
|
98
|
+
- Proper equals, hashCode, toString (Items 10-12)
|
|
99
|
+
- Defensive copies for any mutable fields (Item 50)
|
|
100
|
+
- @Override annotations (Item 40)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Example 2 — Strategy Enum:**
|
|
104
|
+
```
|
|
105
|
+
User: "Model different payment processing strategies"
|
|
106
|
+
|
|
107
|
+
You should generate:
|
|
108
|
+
- Enum with abstract method and constant-specific implementations (Item 34)
|
|
109
|
+
- Strategy pattern via enum (avoiding switch on enum)
|
|
110
|
+
- EnumSet for combining payment options (Item 36)
|
|
111
|
+
- EnumMap for payment-method-to-processor mapping (Item 37)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Example 3 — Thread-Safe Service:**
|
|
115
|
+
```
|
|
116
|
+
User: "Build a caching service that handles concurrent access"
|
|
117
|
+
|
|
118
|
+
You should generate:
|
|
119
|
+
- ConcurrentHashMap for thread-safe cache (Item 81)
|
|
120
|
+
- Documented thread safety level (Item 82)
|
|
121
|
+
- Lazy initialization with double-check idiom if needed (Item 83)
|
|
122
|
+
- Composition over inheritance for wrapping underlying store (Item 18)
|
|
123
|
+
- Try-with-resources for any closeable resources (Item 9)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Mode 2: Code Review
|
|
129
|
+
|
|
130
|
+
When reviewing Java code, read `references/review-checklist.md` for the full checklist.
|
|
131
|
+
Apply these categories systematically:
|
|
132
|
+
|
|
133
|
+
### Review Process
|
|
134
|
+
|
|
135
|
+
1. **Object creation** — Are static factories, builders, DI used appropriately? Any unnecessary object creation?
|
|
136
|
+
2. **Class design** — Minimal accessibility? Immutability where possible? Composition over inheritance?
|
|
137
|
+
3. **Generics** — No raw types? Proper wildcards? Typesafe?
|
|
138
|
+
4. **Enums and annotations** — Enums instead of int constants? @Override present? Marker interfaces used correctly?
|
|
139
|
+
5. **Lambdas and streams** — Used judiciously? Side-effect-free? Not overused?
|
|
140
|
+
6. **Method design** — Parameters validated? Defensive copies? Overloading safe? Return types appropriate?
|
|
141
|
+
7. **General programming** — Variables scoped minimally? For-each used? Standard library utilized?
|
|
142
|
+
8. **Exceptions** — Used for exceptional conditions only? Appropriate types? Documented? Not ignored?
|
|
143
|
+
9. **Concurrency** — Thread safety documented? Proper synchronization? Modern utilities used?
|
|
144
|
+
10. **Serialization** — Java serialization avoided? If present, proxies used?
|
|
145
|
+
|
|
146
|
+
### Review Output Format
|
|
147
|
+
|
|
148
|
+
Structure your review as:
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
## Summary
|
|
152
|
+
One paragraph: what the code does, which patterns it uses, overall assessment.
|
|
153
|
+
|
|
154
|
+
## Strengths
|
|
155
|
+
What the code does well, which Effective Java items are correctly applied.
|
|
156
|
+
|
|
157
|
+
## Issues Found
|
|
158
|
+
For each issue:
|
|
159
|
+
- **What**: describe the problem
|
|
160
|
+
- **Why it matters**: explain the bug, maintenance, or performance risk
|
|
161
|
+
- **Item to apply**: which Effective Java item addresses this
|
|
162
|
+
- **Suggested fix**: concrete code change
|
|
163
|
+
|
|
164
|
+
## Recommendations
|
|
165
|
+
Priority-ordered list of improvements, from most critical to nice-to-have.
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Common Anti-Patterns to Flag
|
|
169
|
+
|
|
170
|
+
- **Telescoping constructors** — Multiple constructors with increasing parameters instead of Builder (Item 2)
|
|
171
|
+
- **Mutable class that could be immutable** — Public setters on a class that doesn't need to change after construction (Item 17)
|
|
172
|
+
- **Concrete class inheritance** — Extending a concrete class for code reuse instead of composition (Item 18)
|
|
173
|
+
- **Raw types** — Using `List` instead of `List<String>` (Item 26)
|
|
174
|
+
- **Overloading confusion** — Overloaded methods with same arity but different behavior depending on runtime type (Item 52)
|
|
175
|
+
- **Returning null instead of empty collection** — `return null` instead of `Collections.emptyList()` (Item 54)
|
|
176
|
+
- **Catching Exception/Throwable** — Over-broad catch blocks that swallow important errors (Item 77)
|
|
177
|
+
- **Using `wait`/`notify`** — When `CountDownLatch`, `CyclicBarrier`, or `CompletableFuture` would be clearer (Item 81)
|
|
178
|
+
- **Mutable Date/Calendar fields** — Exposing mutable `Date` or `Calendar` objects without defensive copies (Item 50)
|
|
179
|
+
- **String concatenation in loops** — Using `+` in a loop instead of `StringBuilder` (Item 63)
|
|
180
|
+
- **Using `float`/`double` for money** — Should be `BigDecimal`, `int`, or `long` (Item 60)
|
|
181
|
+
- **Ignoring return value of `Optional`** — Calling `.get()` without `.isPresent()` check or using `orElse`/`orElseThrow` (Item 55)
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## General Guidelines
|
|
186
|
+
|
|
187
|
+
- Be practical, not dogmatic. Not every class needs a Builder; not every hierarchy needs interfaces.
|
|
188
|
+
Apply items where they provide clear benefit.
|
|
189
|
+
- The three goals are **correctness** (bug-free), **clarity** (easy to read and understand),
|
|
190
|
+
and **performance** (efficient where it matters). Every recommendation should advance at least one.
|
|
191
|
+
- Modern Java (9+) features like modules, `var`, records, sealed classes, and pattern matching
|
|
192
|
+
complement Effective Java items. Recommend them where appropriate.
|
|
193
|
+
- When a simpler solution works, don't over-engineer. Bloch himself emphasizes minimizing complexity.
|
|
194
|
+
- For deeper item details, read `references/items-catalog.md` before generating code.
|
|
195
|
+
- For review checklists, read `references/review-checklist.md` before reviewing code.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|