Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8247379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:49:52+00:00 2026-06-07T22:49:52+00:00

I asked this question several weeks ago and received some good answers: ASP.NET Class

  • 0

I asked this question several weeks ago and received some good answers: ASP.NET Class Library best practice. I now have another question.

The problem I have is that I have inherited an ASP.NET application, which contains lots of classes with tight coupling and low cohesion, which is not ideal. I want to share some of the code with other apps. Most of the code exists in one class, however the class references other classes and those classes reference other classes etc. Is there any way of sharing the code in one class (which references other classes)? The only way I can think of doing this is using web services, but there is sensitive information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:49:54+00:00Added an answer on June 7, 2026 at 10:49 pm

    The only good option, in cases like this, is refactoring the code. You don’t have to change the existing class interface, however. You can create multiple new classes that are designed properly and replace the logic in the original poorly designed class. Then you can refactor the original class to use the new classes internally to perform the functionality. You don’t have to do this all at once. As you find that you need a particular bit of logic in a shared library, just refactor that logic and leave the rest untouched. Over time you can, in this way, refactor the whole thing. Unless, of course, it’s not that big or you have all the time in the world to refactor the beast. However, usually that’s not the case.

    For instance, let’s say you have the following overly simplified classes:

    Public Class OriginalBeast
        Private _dependency As New Dependency()
    
        Public Function Method1() As Integer
            Return _dependency.Calculate(2)
        End Sub
    
        Public Function Method2() As Integer
            Return _dependency.Calculate(2)
        End Sub
    
        ' ...
    
        Public Function Method1027() As Integer
            Return _dependency.Calculate(1027)
        End Sub
    End Class
    
    Public Class Dependency
        Public Function Calculate(value As Integer) As Integer
            Return value * 2
        End Function
    End Class
    

    And you want to share the logic in OriginalBeast.Method2 in a class library, you would need to move the Dependency class to the class library (and likely need to partially refactor it as well). Then you would need to create a new class that contains just the desired methods from the original beast:

    Public Interface INice
        Function Method2() As Integer
    End Interface
    
    Public Class Nice
        Implements INice
    
        Public Sub New(dependency As IDependency)
            _dependency = dependency
        End Sub
    
        Private _dependency As IDependency
    
        Public Function Method2() As Integer Implements INice.Method2
            Return _dependency.Calculate(2)
        End Function
    End Class
    
    Public Interface IDependency
        Function Calculate(value As Integer) As Integer
    End Interface
    
    Public Class Dependency
        Implements IDependency
    
        Public Function Calculate(value As Integer) As Integer Implements IDependency.Calculate
            Return value * 2
        End Function
    End Class
    

    Then, you would need to refactor the original beast to use the class library instead of doing the logic itself:

    Public Class OriginalBeast
        Public Sub New()
            _dependency = New Dependency()
            _nice = New Nice(_dependency)
        End Sub
    
        Private _dependency As IDependency
        Private _nice As INice
    
        Public Function Method1() As Integer
            Return _dependency.Calculate(2)
        End Sub
    
        Public Function Method2() As Integer
            Return _nice.Method2()
        End Sub
    
        ' ...
    
        Public Function Method1027() As Integer
            Return _dependency.Calculate(1027)
        End Sub
    End Class
    

    Obviously real-world beasts are never that simple and it will likely require a lot of work to refactor even a small part of it, but hopefully that gives you an idea of what I’m talking about.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've already asked this question on several forums, but without any good explanation of
I asked this question: Is ASP.NET MVC destined to replace Webforms? and a few
I have seen this question asked several times but the answers have so far
Recently I asked this question: Find Common Values in several arrays, or lists VB.NET
I know that this question has been asked several times and I've read all
I have tried looking though several of the already asked question about this topic
This question has been asked several times already, but has been solved with poor
I know this question has been asked several times, but I can't quite seem
I know this question would have been asked several time but still I am
I asked a similar question a few weeks ago on how to split a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.