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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:56:40+00:00 2026-05-11T08:56:40+00:00

Imagine these relationships: 1 A has many B’s 1 B has many C’s… In

  • 0

Imagine these relationships:

  • 1 A has many B’s
  • 1 B has many C’s…

In reverse:

  • C has 1 B
  • B has 1A
  • By transitivity, C has 1 A

To model this relationship in DB, we have:

TableA a_id  TableB b_id a_id (fk to TableA)  TableC c_id b_id (fk to TableB) 

To model this relationship in OO, we have:

objA objB objC 

And… – objB has reference to objA – objC has reference to objB

If objC has a method that needs to call a method of objA, what will you do?

Option 1.

b.getA().runMethodX() 

Many ppl I know would do this, but I’ve also learned that this is not good because getA() is not a behavior of B in a pure OO sense. Doing so is just like doing procedural programming. Agree/Disagree?

Option 2.

Let objC has direct reference to objA and objB through constructor injection / setter

Is this a good idea? but then objB that objC has reference to also has reference to objA. Is this okay? Or as long as it is not a case of cyclic object references, it is acceptable?

Option 3.

Move the method in question to objA, and pass objC in by parameter.

I’m not sure if this considers as an option. I think it’ll not work in every case. Have the method in objC reduce to bare minimum that only works on its states, and let objA do whatever objA needs to do before or after.

Option 4. (Delegation)

add runMethodXinA() to B, it calls

a.runMethodX() 

C calls

b.runMethodXinA() 

I tried this method before, but B will very likely end up having as many methods as A, and doesn’t having 1 method in both B and A violates DRY?

What are your though? Any other options? Comments? Suggestions?

  • 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. 2026-05-11T08:56:41+00:00Added an answer on May 11, 2026 at 8:56 am

    Option 2 is a fairly dangerous duplication of information, in addition to whatever issues may come out of the shape of the reference graph depending on your environment.

    Option 3 might make sense if the method is in some sense dependent on the type of objA, as a sort of double dispatch.

    Option 1 goes against the Law of Demeter, but it sounds like it’s the least intrusive option.

    You may also want to consider a forwarding method on objB that passes the call to objA.

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

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Something like this should get you started: var timeout; $('input[type=text]').keypress(function()… May 11, 2026 at 11:17 am
  • added an answer set a css rule on #response to have display: none… May 11, 2026 at 11:17 am
  • added an answer Not directly pv3d related but, could help ... It sounds… May 11, 2026 at 11:17 am

Related Questions

Imagine I have these python lists: keys = ['name', 'age'] values = ['Monty', 42,
I imagine there are many of you out there who have developed an application
On C# 3.0 and .NET 3.5, imagine there's an interface: public interface INameable {
Is there any way to check if a particular plugin is available? Imagine that
There is one thing that I do not understand... Imagine you have a text
I have what I imagine to be a pretty standard web-interface. There are 4
Imagine you homebrew a custom gui framework that doesn't use windows handles (compact framework,
Imagine we have a program trying to write to a particular file, but failing.
Imagine you want to animate some object on a WinForm. You setup a timer
Imagine an object you are working with has a collection of other objects associated

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.