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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:16:51+00:00 2026-05-22T17:16:51+00:00

Here is a generic imaginary example made up for this post. Consider 6 classes

  • 0

Here is a generic imaginary example made up for this post. Consider 6 classes

TableFactory, TableData, TableCRUD, TableSchema, DBConnect, Logger. 

TableFactory is the outer class, let’s say it holds a TableData object for a DB table.

In this TableFactory, there are no calls to TableSchema or DBConnect or logger. I am aiming for an example of inner objects not needed in outer scope.

TableData is an inner fetches and operates on the data, so it needs TableCrud, DBConnect and Logger.

TableCrud contains TableSchema and needs DBConnect, and Logger.

DbConnect itseld, to make things fun, needs a Logger. My example is now 3 scopes deep.

My Question is pretty simple, if you have an object 3 (or more) scopes in that are not called upon by objects on outer scope, how does one send those objects from outer to inner scope without breaking the Interface Segregation Principle -> TableFactory shouldn’t have to deal with DBConnect or Logger needed by inner objects.

If one respects basic OOP principles and aims for easy testability -> you would have outer objects needing injection of the 5 objects, and then have getter methods that woud pass the objects needed further up the chain. And inner scoped objects would in turn require injection of the dependencies of their inner 3-scope-deep objects, with getters for those too. This makes for outer scoped objects requiring many dependencies, and getters just to pass those on.

Is there an alternative to this object-passing methodology, something I missed along the way? Please share! Any links/comments appreciated.

  • 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-22T17:16:52+00:00Added an answer on May 22, 2026 at 5:16 pm

    It’s a common misconception that dependencies need to be passed through the object graph. To summarize the example Miško Hevery gives in Clean Code: Don’t look for things, a House that needs a Door, doesnt need to know about the Lock in the Door:

    class HouseBuilder
    {
        public function buildHouse()
        {
            $lock  = new Lock;
            $door  = new Door($lock);
            $house = new House($door);
    
            return $house;
        }
    }
    

    As you can see, House is completely oblivious of the fact that the Door in it requires a lock. It’s the responsibility of the HouseBuilder to create all the required dependencies and stack them together as they are needed. From the inside out.

    Consequently, in your scenario you have to identify which objects should operate on which dependencies (cf Law of Demeter). Your Builder then has to create all collaborators and make sure the dependencies are injected into the appropriate objects.

    Also see How to Think About the “new” Operator with Respect to Unit Testing

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

Sidebar

Related Questions

This is a very generic 'best practice' question, but here's an example. Let's say
Talking about System.Collections.Generic.List<T> here. With example below can Method1 and Method2 execute and the
I have a generic list of objects in C#, for example sake, here's what
I have three classes: Generic, CFG, and Evaluator. Here's Generic: class Generic: public virtual
For the sake of this question, here is my generic class. [ComVisible(true)] public class
What does this error mean? Generic.h:25: error: 'Generic' is not a template type Here's
This is the follow up of my question here: Weird Java generic . If
Here's an example: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SharpLibrary_MediaManager {
Here is a generic question. I'm not in search of the best answer, I'd
Here's the situation: We have some generic graphics code that we use for one

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.