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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:33:05+00:00 2026-06-06T00:33:05+00:00

An important property of really SOLID code is the fact that constructor calls do

  • 0

An important property of really SOLID code is the fact that constructor calls do not often happen within the actual application code but primarily in the composition root and factory methods where necessary.
This makes a lot of sense to me, and I adhere to this wherever I can.

I have created a simple class where it seems to me it is not only allowed, but actually correct to deviate from the above rule.
This abstracts some simple Registry queries to facilitate unit testing of some other code:

public class RegistryKeyProxy : IRegistryKey
{
    private RegistryKey registrykey;

    public RegistryKeyProxy(RegistryKey registrykey)
    {
        this.registrykey = registrykey;
    }

    public IRegistryKey OpenSubKey(string subKeyName)
    {
        var subkey = this.registrykey.OpenSubKey(subKeyName);

        return (null == subkey ? null : new RegistryKeyProxy(subkey));
    }

    public IEnumerable<string> GetSubKeyNames()
    {
        return this.registrykey.GetSubKeyNames();
    }

    public object GetValue(string valueName)
    {
        return this.registrykey.GetValue(valueName);
    }
}

The OpenSubKey() method actually creates an instance of this same class without using a factory, but because of the closed concept that the Registry presents, it actually seems desirable to me not to return anything that looks like a Registry key, but really something that works exactly the same way as the current object.

I know that in the end it’s up to me just how SOLID I want to work, but I’d like to know if this generally is a feasible path to go because of the nature of the underlying concept, or if this is not an exception to the rule but actually a SOLID violation.

  • 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-06T00:33:08+00:00Added an answer on June 6, 2026 at 12:33 am

    You are talking about the Dependency Inversion principle. This principle doesn’t say that you should never new up objects at all, but it differentiates between two types of objects. Objects that implement behavior (services), and objects that contain data (DTOs, Value Types, Entities).

    It would be rather silly in not newing up DTOs, since there is no behavior to be abstracted. They just contain data. (Just as would be silly to add an IPerson interface to a Person DTO).

    Miško Hevery calls them injectables and newables, which is an nice terminolgoy.

    For more information, see this Stackoverflow question: Why not use an IoC container to resolve dependencies for entities/business objects?

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

Sidebar

Related Questions

Why is there a DataGridViewRow.Cells property, but not a DataGridViewColumn.Cells property? What's so important
Screenshot Important Note : This application does not support Internet Explorer. I will be
I know that you can either step into every property or not step into
How is the CSS attribute property !important read? Is it really important , exclamation
I do not really use any try/catches in my code ever but I'm trying
Some important part of my code is running in viewDidLoad and I was wondering
There is very important shortcut for "Basic Code Completion" in IntelliJ IDE which assumed
Is it really important to know algorithms to build mobile applications? I have strong
The two most important fields, that are everywhere in our warehouse, are the UserAccountKey
Suppose that I have the following mapping with a formula property: <class name=Planet table=planets>

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.