Skip to content

refactor: Replace inheritance with ZVecQueryInterface for query types#143

Merged
s2x merged 1 commit into
mainfrom
feat/smell-012-query-interface
May 30, 2026
Merged

refactor: Replace inheritance with ZVecQueryInterface for query types#143
s2x merged 1 commit into
mainfrom
feat/smell-012-query-interface

Conversation

@s2x

@s2x s2x commented May 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces inheritance-based design (ZVecGroupByVectorQuery extends ZVecVectorQuery) with composition via ZVecQueryInterface.

Closes #93

Changes

  • New: ZVecQueryInterface with getHandle(): FFI\CData and free(): void
  • Refactored: ZVecVectorQuery implements ZVecQueryInterface, owns its destructor with $closed flag
  • Refactored: ZVecGroupByVectorQuery implements ZVecQueryInterface independently (no extends)
  • Removed: $handleType property and branching destructor from ZVecVectorQuery
  • Improved: free() is idempotent (safe to call multiple times)

Motivation

SMELL-012: The previous design had three problems:

  1. ZVecGroupByVectorQuery inherited setter methods that called wrong FFI functions (zvec_vector_query_set_* on a group_by handle)
  2. Destructor used branching on $this->handleType violating Open/Closed Principle
  3. Adding new query types required modifying the parent destructor

Testing

  • All 132 existing tests pass (no regressions)
  • New test tests/test_query_interface.phpt verifies interface contract, independence of both types, idempotent free(), and functional queries

- Add ZVecQueryInterface with getHandle() and free() methods
- ZVecVectorQuery implements ZVecQueryInterface, owns its destructor
- ZVecGroupByVectorQuery implements ZVecQueryInterface independently (no extends)
- Remove handleType branching from ZVecVectorQuery destructor
- Each query type manages its own handle lifecycle via free() idempotency
- All 132 tests pass

Closes #93
@s2x s2x changed the title refactor: Replace inheritance with ZVecQueryInterface for query types (#93) refactor: Replace inheritance with ZVecQueryInterface for query types May 30, 2026
@s2x s2x merged commit 3dcbd51 into main May 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SMELL-012: ZVecGroupByVectorQuery Misuses Inheritance

1 participant