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 8726689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:18:01+00:00 2026-06-13T08:18:01+00:00

How can I determine or tell if a set of classes are spaghetti code?

  • 0

How can I determine or tell if a set of classes are “spaghetti code”?

Should I look at my code as being spaghetti when I generate a Dependency Graph in Visual Studio under the Architecture menu, and see that there are a lot of curvy arrows pointing all over the place?

I always avoid the problem of spaghetti code by attempting to reduce the amount of dependencies between the classes. When doing so, yes, the Dependency Graph indeed becomes neater. And when I make changes to certain part, because the classes have little dependency between each other, I don’t have to worry about messing up the other classes.

But, by doing this method, sometimes, it appears that I have to repeat some code. For example, I could have the following object that’s stored in a list:

class DataBlock {
   public int id;
   public string name;
   public SomeObject dataObj;

   public Object[] Data1 { get { return dataObj.RetrieveInfo(); } }

   public Object[] Data2 { get { return dataObj.SomeProperty; } }

   public bool DoCompare(obj) { ... }
}

So, there is a list called DataList of the type List<DataBlock> consisting the above object.

And then now, suppose I am going to dispatch an event that will include some information from DataBlock. I could include this whole DataBlock object into the EventArgs. The handler function can then just do this:

void Handler(MyEventArgs evtArgs) {
   DataBlock data = evtArgs.Data;
   var firstData = data.Data1;
   data.Data2;
   firstData.DoCompare(data.Data2)
   data.name;  //etc, etc
}

This is convenient. But, this would also mean that the class that has this handler will then now have dependencies on the DataBlock object. So, one of my ways to get rid of this, is within my EventArgs, I repeat all those informations from DataBlock, like this:

class MyEventArgs : EventArgs {

   public MyEventArgs(id, name, data1, data2) {
      ID = id;
      Name = name;
      Data1 = data1;
      Data2 = data2;
   }
   public int ID { get; private set; }
   public string name { get; private set; }
   public Object[] Data1 { get; private set; }
   public Object[] Data2  { get; private set; }
}

By arranging my EventArgs this way, both my EventArgs and whichever class having the event Handler will not have dependency on the DataBlock. Only the firer of the event knows about the DataBlock and it rips off the data from DataBlock and put them into MyEventArgs via its constructor. However, now, the problem in this is, the MyEventArgs is repeating every getters/setters that is inside Datablock. And, I also lose access to all helper methods within DataBlock!

This is just a small example of a problem that I often face. There are more serious ones where I found myself repeating the getters/settings for a few classes, just because I want to reduce the dependency.

Other problems that I face that show up a lot of arrows on the Dependency Graph, is when, say, I have an interface called ISomeObject. Because the ISomeObject is a popular object within the classes, the interface is used by many other parts of the classes. In the end, there are tons of arrows pointing to the ISomeObject. Would this imply spaghetti code too?

It’s difficult for me to explain the problems I face when I want to keep my code organised. But I hope the examples above are enough to illustrate what I want to tell.

So, what are the best practices for a scenario like this? Should I determine that my code is spaghetti when the Dependency Graph in Visual Studio shows a lot of messy curvy arrows pointing all over the place?

  • 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-13T08:18:02+00:00Added an answer on June 13, 2026 at 8:18 am

    I honestly believe that spaguetti code ins’t something tied to dependencies or such higher level things.

    Spaguetti code is an anti-pattern that consists on creating a highly-coupled code with no order and completely irrational, meaning that author – programmer(s) – will hardly explain code flow for you.

    One of most important symptoms of spaguetti code is that it’s unmaintainable: if you fix a bug, it creates one or more bugs. When you fix these bugs, you get more bugs. And finally code is fixed by hardcoding garbage everywhere.

    Again, I doubt that a large object graph with a lot of dependencies would be “spaguetti code”.

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

Sidebar

Related Questions

Please tell, how can i determine, the browser supports canvas (paperjs), or not ?
How can you determine which rubygem is being used in response to a require
I can set up an event listener to tell me when a mouse click
I can determine the current number of connections by db.serverStatus().connections but all that gives
Can somebody please let me know how we can determine if a local disk
How can I determine the absolute path of a file or directory from a
How can I determine the used size/length of a buffer created with create_string_buffer? buffer
How can I determine in KeyDown that ⇧ + Tab was pressed. private void
How can I determine the address in memory of the Java heap for a
How can I determine programmatically whether my machine is an x86, x64 or an

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.