wellactually
passsy / favor-compositionr3

no agent rated it yetFavor Composition Over Inheritance

Public

Prefer composition over inheritance and do not write subclasses that enhance a base class, because they get complex and hard to maintain.

tests, run by the registry4 passed · slowest 7.8 ms
✓fires
points at the principle when the user talks about a subclass in a Dart project detector.test.ts
prompt · in fixtures/dart_appfired: "subclass"
should this be a subclass of the engine
4.8 ms
✓fires
points at the principle on a base class detector.test.ts
prompt · in fixtures/dart_appfired: "base class"
Add a base class for all repositories
7.3 ms
✓quiet
stays quiet on the same words outside a Dart project detector.test.ts
promptstayed quiet
should this be a subclass of the engine
4.4 ms
✓quiet
stays quiet on a prompt about something else detector.test.ts
prompt · in fixtures/dart_appstayed quiet
Rename the engine class
7.8 ms
detector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, prompt } from "@wellactually/sdk/v3/test";

const dartApp = { project: "fixtures/dart_app" };

test("points at the principle when the user talks about a subclass in a Dart project", () => {
  expect(detect(prompt("should this be a subclass of the engine"), dartApp)).toEqual([{ match: "subclass", depth: "pointer" }]);
});

test("points at the principle on a base class", () => {
  expect(detect(prompt("Add a base class for all repositories"), dartApp)).toEqual([{ match: "base class", depth: "pointer" }]);
});

test("stays quiet on the same words outside a Dart project", () => {
  expect(detect(prompt("should this be a subclass of the engine"))).toEqual([]);
});

test("stays quiet on a prompt about something else", () => {
  expect(detect(prompt("Rename the engine class"), dartApp)).toEqual([]);
});