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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:17:12+00:00 2026-05-25T22:17:12+00:00

I have a base class of FileCopier that is composed with two has-a associations

  • 0

I have a base class of FileCopier that is composed with two “has-a” associations to Resource Source and Resource Destination.

After construction, three properties exist in FileCopier:

- Source (instance of Resource)
- Destination (instance of Resource)
- Config (array of configuration stuff for this FileCopier)

All of the examples I find on this issue are regarding children by extension rather than children by composition.

My question is: is there any way for the Resource instance to access it’s parent’s “Config”?

Or, must I pass a reference to the parent to it’s associated children, say, via the constructor?

  • 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-25T22:17:13+00:00Added an answer on May 25, 2026 at 10:17 pm

    If I understand well you have:

    class FileCopier{
        /* @var Source */
        private $source;
    
        /* @var Destination */
        private $destination;
    
        /* @var Config */
        private $conf;
    
        ...
    
    }
    

    And you want to access $conf from $source and $destination?
    There is no parent or other magic word to access this $conf from the two other variables.
    Your best bet would be to add a function to Resource which will set a local reference to Config:

    class Resource {
        /* @var Config */
        protected $config;
        ...
        function setConfig(Config $config) {
            $this->config = $config;
        }
        ...
    }
    

    Or if config is set at some other point r could change or if for whatever other reason you want to access the latest $conf from your resources you can pass a ref to FileCopier instead:

    class Resource {
        /* @var FileCopier */
        protected $copier;
        ...
        function setFileCopier(FileCopier $copier) {
            $this->copier = $copier;
            // and access to $this->copier->conf through a getter
            // or make $conf public in FileCopier
        }
        ...
    }
    

    Then all you have to do is to call your setter before using $source and $destination. Probably in the FileCopier:

    class FileCopier{
        ...
        //first case :
        function setConfig($config) {
            $this->config = $config;
            $this->source->setConfig($config);
            $this->destination->setConfig($config);
        }
    
        // Or for the second case:
        function setup() {
            $this->source = new Source();
            $this->source->setFileCopier($this);
    
            $this->destination = new Destination();
            $this->destination->setFileCopier($this);
        }
    
        ...
    
    }
    

    Hope this helps.

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

Sidebar

Related Questions

I have a base class ActivityA that has some dialogs: public static final int
I have a base class Foo that has an Update() function, which I want
I have a base class that has methods that use a generic type in
I have a base class that owns a managed disposable resource (.NET PerformanceCounter). I
I have base class that is called Entity. Then I have two child class
I have a base class, Sport, that has a property will return the proper
I have a base class that has an abstract getType() method. I want subclasses
I have a base class in Ruby that has a class method which it
I have a base class ( car ) and a class that inherit the
I have a Base class, that is considered read-only, and in it's virtual desructor

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.