90% code reduction through SOLID principles and a reflection-based framework

How a custom database access framework transformed a legacy codebase from 4,000-line classes to 400 lines

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.

What we did

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.

The results

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.

What the client had at the end

  • 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

More work like this

Not sure which one? That is what the call is for.

Thursday afternoons are usually free. Straight into my calendar, no qualification call before the qualification call.