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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:58:46+00:00 2026-06-16T15:58:46+00:00

In my program, some objects need other objects (dependency), and I’m using Factory as

  • 0

In my program, some objects need other objects (dependency), and I’m using Factory as my creational pattern.

Now, how do I solve a simple dependency problem?

This is an example of what I’m doing to solve my problem. I want to know if sending the needed objects to the Create method is not something horribly wrong.

//AbstractBackground
// - SpecialBackground
// - ImageBackground
// - NormalBackground
class Screen{
    List<AbstractBackground> list;
    Cursor cursor;
    ContentManager content;

    public void load(string[] backgroundTypes){
        //is this okay? --------------->
        AbstractBackground background = BackgroundFactory.Create(backgroundTypes[0], cursor, content);
        list.add(background);
    }
}

class BackgroundFactory{
    static public AbstractBackground Create(string type, Cursor cursor, ContentManager content){

        if( type.Equals("special") ){
            return new SpecialBackground(cursor, content);
        }

        if( type.Equals("image") ){
            return new ImageBackground(content);
        }

        if( type.Equals("normal") ){
            return new NormalBackground();
        }
    }
}
  • 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-16T15:58:48+00:00Added an answer on June 16, 2026 at 3:58 pm

    Simple answer, it looks good. If you think of this abstractly, you are injecting the objects into the constructor through the create method. Nothing wrong with this technique, and is something that I recommend.

    Later, if you need to change the implementation, you can create other create methods as needed without breaking anything.

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

Sidebar

Related Questions

in a C++ program I need some helper constant objects that would be instantiated
I have a C program that stores some object in java store using JNI.
I am developing some program in C# which will send the mail using outlook
in a program I'm writing I'm creating some objects with a start date (with
I have a program where I need to do some initial work before calling
I am working on a program and need to make an array of objects,
I'm writing an analyzer,which shows the packets of a specific program.Some packets are very
Question What would be a good (ideally, technical) reason to ever program some non-trivial
My program does some network activity in a background thread. Before starting, it pops
My program uses some external programs that i included in the Files folder. In

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.