90% Code Reduction Through SOLID Principles and Reflection-Based Framework
How a custom database access framework transformed a legacy codebase from 4,000-line classes to 400 lines
Key results at a glance
The challenge
The Problem
A law firm had a legacy technology stack spanning VB6, Silverlight, WPF, and ASP.NET MVC. The most significant issue: pervasive code duplication.
The Duplication Pattern
Database access code was copy-pasted throughout:
- 6-8 lines repeated for each property retrieval
- Hardcoded string references to property names
- Individual database connections opened for every single query
- 10+ interactions scattered across the codebase for a single task
This wasn't just inefficient - it was unmaintainable. Any change to database access patterns required updating dozens of locations.
The results
Key results
- Class sizes reduced from 4,000 lines to 400 lines (90% reduction)
- Database interactions reduced from 5-8 lines to single line
- Reflection-based framework with nameof() pattern for type safety
- Shared authorisation packages eliminating cross-application duplication
- Measurable demonstration of SOLID principles impact
Outcomes
Code Reduction
- Database interactions reduced from 5-8 lines to single line
- Class sizes reduced from 4,000 lines to 400 lines in the target library
- 90% reduction in code volume
Maintainability
- Single point of change for database access patterns
- Type-safe property references eliminating runtime errors
- Clear separation of concerns through repository pattern
Foundation for Future
- Shared authorisation packages eliminating cross-application duplication
- Framework approach applicable to other areas of the codebase
- Pattern demonstrating measurable ROI of clean code practices
Lesson Learned
This engagement demonstrated that clean code practices deliver measurable, demonstrable results. The 90% reduction wasn't abstract quality improvement - it was concrete, countable improvement in maintainability and developer productivity.
The solution
Our Approach
We built a reflection-based database access framework from scratch.
Framework Design
- Dictionary-like property access: Establishing a context on entry, then accessing properties via generated const strings
- nameof() pattern: Type-safe property references eliminating hardcoded strings
- Centralised connection management: Single point of database access control
- Repository pattern: Clean separation of data access concerns
Application
Applied the framework alongside repository patterns to demonstrate measurable impact on a specific legacy library.
Additional Cleanup
Also identified duplicated authorisation logic across the Silverlight component ecosystem and began developing shared packages to centralise these concerns.
Ready to achieve similar results?
Let's discuss how we can help your organisation achieve these results.
Book a strategy call