Refactoring: Boundaries

Please see my other Web Development articles.

Ensuring Separation of Concerns

When refactoring a web application, the following table represents a high-level overview of technologies/tools and the appropriate use of each, along with examples of how their boundaries for us may be violated.
Keep in mind for each tool is intended boundary and look for example violations when seeking areas to improve your application through refactoring.

Technology Boundary/Layer Violation/Issue
JavaScript Client logic/UI layer JavaScript in HTML combines concerns by injecting behavior into markup, prevents caching and reuse.
Insert JavaScript into C# to create dynamic JavaScript. JSon should be used.
HTML Client markup/UI layer HTML mixed with the Database query results, combining presentation markup and data storage together, hindering reuse.
CSS Client styling/layout/UI layer CSS inline within HTML, limiting reuse, increasing maintenance costs (duplicates), mixes semantic markup & styling, prevents caching, reuse.
C# Server logic/middle layer
SQL Data access/data layer SQL mixed with C# to make dynamic SQL. Use LINQ instead.

In addition, using each technology within its boundaries provides the following examples of benefits:

  • Caching/Reuse: JavaScript maintained only in .js files (not mixed with HTML or injected with C#) allows browsers to load once, then cache for future reuse.
  • Keyword-formatting & Syntax validation: Each language maintained in their native files allowed the IDE (Visual Studio) format keywords for helpful display and provide valuable design-time validation to avoid bugs before code use.
  • Separation of Concerns: Language files being maintained separately allows developers to more quickly isolate bugs and apply fixes, and aid in productivity/collaboration as specific development tasks may target specific files, avoiding having to change other files being changed by other developers.
  • Code Reuse: Each language maintained in their native files allows OOP techniques to provide resuse of common behavior.