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

  • Home
  • SEARCH
  • 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 7496625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:42:03+00:00 2026-05-29T18:42:03+00:00

So here is my problem: For instance, consider that: A File has a set

  • 0

So here is my problem:

For instance, consider that:

A File has a set of Classes, as well as Imports.

A Class has a set of Instance Methods, Static Methods and Variables.

A Instance Method has Parameters and a Body.

The Body has … yadayada.

The problem, when modelling this in a OO way is that Body may need a lot of specific dependencies to function:

class Body {
    ...

    public Body(Dependency1, Dependency2, Dependency_n, ...) { }

    ...
}

that all the other classes won’t need, to run. The question I’m putting here is on how to get those dependencies to Body without having to pass all this dependencies through File, Class and InstanceMethod.

I could create a BodyFactory, but the problem would still be the same, as I’d have to pass the BodyFactory through File, Class and InstanceMethod, if I’m not missing anything.

How to solve this issue without resorting to singletons?

  • 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-05-29T18:42:06+00:00Added an answer on May 29, 2026 at 6:42 pm

    Let Body implement an IBody interface and let InstanceMethod depend only on IBody and IEnumerable<IParameter> (if we assume C# – in Java it would be a differently named collection interface, but the principle would be the same).

    Repeat this process of refactoring to Facade Services all the way to the Composition Root, where you can then compose the entire object graph like this:

    File file = new File(
        new List<IClass>
        {
            new Class(
                 new List<IInstanceMethod>
                 {
                     new InstanceMethod(
                         new List<IParameter>(),
                         new Body(
                             new Dependency1()
                             new Dependency2(),
                             new DependencyN()))
                 },
                 new List<IStaticMethod>(),
                 new List<IVariable>())
        },
        new List<IImport>());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a strange problem here... I have an ASP.NET 3.5 application that has
I've got a strange problem here. Assume that I have a class with some
I've got a problem here with an MSI deployment that I'm working on (using
Consider the following code :- public class UsingWait1{ public static void main(String... aaa){ CalculateSeries
Here is an interesting problem that I encountered in a programming competition: Problem statement:
I have an interesting problem. Consider this class hierachy: class Base { public: virtual
Hia, I got a somewhat odd problem. Im using two managed Classes that relate
Here are my classes : class PriceScale -int ID -float bookingFees -Product product -List<PricePeriod>
I have a small problem here and hope that someone can help me out.
Maddening problem here. When my page loads: <body onload=getClientDateTime();> It runs this function: document.getElementById('ClientDateTime').value=hello

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.