[Issue #37] Replace interface{} with properly defined interfaces #42
Reference in New Issue
Block a user
Delete Branch "issue-37-replace-interface"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #37
Summary
VirtualMachineinterface withGetID(),GetActorID(),GetState()for type-safe VM accessRuntimeModelandRuntimeMessageinterfaces for event storming model and actor message contractsVMProviderinterface for decoupled VM access in cluster registryVMRegistry.GetActiveVMs()to returnmap[string]VirtualMachineinstead ofmap[string]interface{}Runtimeinterface to use proper types instead ofinterface{}DistributedVMRegistryto use dependency injection viaVMProviderTest plan
Generated with Claude Code
- Add VirtualMachine interface with GetID(), GetActorID(), GetState() - Add VMState type with idle/running/paused/stopped states - Add RuntimeModel interface for event storming model contracts - Add RuntimeMessage interface for actor message contracts - Add VMProvider interface for decoupled VM access - Update VMRegistry.GetActiveVMs() to return map[string]VirtualMachine - Update Runtime interface to use RuntimeModel and RuntimeMessage - Update DistributedVMRegistry to use VMProvider instead of interface{} - Add SetVMProvider method to DistributedVM for dependency injection This improves type safety, makes contracts explicit, and enables better IDE support while avoiding import cycles through interface segregation. Closes #37 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>Code Review: PR #42 - Replace interface{} with properly defined interfaces
Overall Assessment
Good refactoring that improves type safety. The changes follow Go best practices for interface design.
Issues to Address
Type Assertion Bug in handleClusterMessage (distributed.go:171-180)
The type assertions will fail at runtime because JSON unmarshals into map[string]interface{}, not concrete types implementing RuntimeModel/RuntimeMessage. The assertion will never succeed.
Fix: Add concrete structs for JSON unmarshaling, or re-marshal and unmarshal the payload.
Verdict
The design is sound. However, the type assertion issue is a functional bug.
Recommendation: Needs Work
JSON unmarshal produces map[string]interface{}, not concrete types. Added ModelPayload and MessagePayload concrete types that implement RuntimeModel and RuntimeMessage interfaces respectively. The handleClusterMessage now re-marshals and unmarshals the payload to convert from map[string]interface{} to the proper concrete type. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>Fix Applied
Addressed the type assertion bug in handleClusterMessage:
ModelPayloadandMessagePayloadconcrete types that implementRuntimeModelandRuntimeMessageinterfaceshandleClusterMessageto re-marshal/unmarshal the payload to convert frommap[string]interface{}to proper concrete typesReady for re-review.
a33ef47a39tob759c7fb97Re-Review: Approved
The type assertion bug has been fixed correctly:
All tests pass, build succeeds. Ready to merge.
Code Review: PR #42 - Replace interface{} with properly defined interfaces
Overall Assessment
Good refactoring that improves type safety by replacing
interface{}with properly defined interfaces. The changes follow Go best practices for interface design.What Works Well
Issues to Address
1. Type Assertion Bug in handleClusterMessage (distributed.go:171-180)
The type assertions will always fail at runtime:
When JSON unmarshals into
interface{}, it producesmap[string]interface{}, not a concrete type implementingRuntimeModel. The assertion will never succeed.Suggested fix: Either:
payloadBytes, _ := json.Marshal(clusterMsg.Payload); json.Unmarshal(payloadBytes, &concreteModel)2. Silent Failures (Minor)
Failed type assertions in
handleClusterMessageare silently ignored. Consider logging when payloads cannot be processed:Verdict
The design is sound and the interfaces are well-structured. However, the type assertion issue in
handleClusterMessagerepresents a functional bug that should be addressed before merging.Recommendation: Needs Work - Please fix the type assertion issue, then this is ready to merge.