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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:24:24+00:00 2026-05-30T17:24:24+00:00

I have two components, A and B. Component B requires that A has a

  • 0

I have two components, A and B.
Component B requires that A has a certain state.

I can write this as part of B’s code,
or I can write this as part of A’s code (and maybe add assertions to B)

What should I take into consideration when making such a decision?

Edit

In this scenario there might be several B-type components.
It’s also assumed that I can’t avoid this situation

Edit 2

This often happens when working with frameworks. I usually have a some sort of “global settings”, and components that require those settings to be something

  • 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-30T17:24:25+00:00Added an answer on May 30, 2026 at 5:24 pm

    Possibilities:

    • Have A implement an interface that will B will check
    • Make A create B whenever it has such a state.

    Generally, the first solution is used, because ALL Bs refer to A, but A doesn’t actually have to know about ALL Bs (you said there were many). In theory, every object should do what it is supposed to do, ignoring anything else exists, unless its a controller object.

    With the first solution, B checks what A has.
    With the second solution, A becomes the controller of all Bs.

    I would say that it’s better to have Bs check for A on creation, but in special cases, like when A is your main controller class, it MIGHT be preferable to have A create B.

    Edit as response to Edit 2 by OP
    Yes, in this case it’s almost always better to have B check in global settings. Global settings are there so you can check them! The only exception is if A is also the owner of all other components (such as the Game class in XNA)… Even there it would be difficult to choose and just to keep the architecture intact I’d still make B check inside of A, it’s just more clean and healthy.

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

Sidebar

Related Questions

I have two components that that communicate via TCP/IP. Component A acts as a
I have an ascx component, that holds two-level menu, because there are several user
I have a project where I am required to fix this program that has
I have two input components on my page . Each of them has a
I have two components A and B. Component B derives from component A and
I have two date picker components and a JComboBox component with their associated Action
I have two components, a base Entity component: <cfcomponent persistent=true> <cfproperty name=Id fieldtype=id generator=native>
I have some component code that I'd like to in a CakePHP Task, but
I have two Document Models that are proving problematic: class Component include Mongoid::Document include
I have a multi-component UIPickerView in my application. Two components are plain and completely

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.