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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:59:18+00:00 2026-05-17T19:59:18+00:00

I am doing the design of a small project where I didn’t use programming

  • 0

I am doing the design of a small project where I didn’t use programming against interfaces for all my classes. I found that some classes would hardly ever be needed to change, so I let them be referenced by their client classes as concrete classes.

So, let’s say we have ClassB that’ll be consumed be consumed by ClassA:

alt text

class ClassB {
}

My question is, should I create ClassB in ClassA, or should I pass that responsability “up” in the hierarchy? I’ll depict both cases:

class ClassA {
    private ClassB classB;

    public ClassA() {
        this.classB = new ClassB();
    }
}

or

class ClassA {
    private ClassB classB;

    public ClassA(ClassB classB) {
        this.classB = classB;
    }
}

I’d like to hear about how would you do it and what’d be the rationale behind it!

Thanks

  • 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-17T19:59:18+00:00Added an answer on May 17, 2026 at 7:59 pm

    Some advantages of your first option (A creates B):

    1. The user of class A needs to know nothing about B or how to create & configure it. This makes for a simpler programming model.
    2. B can also be made private/internal, so that users of your library don’t need to wade through lots of helper classes they don’t need to see.
    3. You can change the way A works to not use B at all without breaking calling code.
    4. Encapsulation – no one gets to tamper with B from the outside while A is running

    Some advantages of your second option (A takes a dependency on B):

    1. The user of class A has full control over the B object – they can configure it differently, they can pass the same one into multiple instances of A if they want.
    2. It opens the door for different implementations to be passed in (if B is an interface or base class) which is of great value for unit testing, or extensibility.
    3. update: if in the future, it becomes more complicated to create B (e.g. B has some dependencies of its own), then that can be managed outside without needing to make changes to A.

    Note that it is also possible to create a “best of both worlds” solution by using what is sometimes called “poor man’s dependency injection”:

    class ClassA {
        private ClassB classB;
    
        public ClassA(ClassB classB) {
            this.classB = classB;
        }
    
        public ClassA() : this(new ClassB()) {
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing some design/debugging in IRB and need to login a user and then
Sorry if this is a stupid noob question. I'm doing a very small project
I'm creating a small program with some design patterns, and I'm trying to implement
I am doing database design for an upcoming web app, and I was wondering
i am doing a database design using EAV. I am facing an issue when
I've been doing web development / design for about five years now, and I
We are currently doing a review of our WCF service design and one thing
I have to design a batleships game for friday but the course im doing
Doing the below will reproduce my problem: New WPF Project Add ListView Name the
As a project over summer while I have some downtime from Uni I am

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.