Solved

Programming Practice - Circular Reference between Dialog Classes

Posted on 2013-01-17
8
388 Views
Last Modified: 2013-01-17
Is it bad practice to make a Circular Reference  between 2 dialog classes?

Example

dialog A                                                          dialog B
 
array = b                                                        dialog B(dialog a, etc, etc) {
                                                                              parent = a;
open dailog B (dailog a, etc, etc)                    }

                                                                      array c = parent.getArrayb;


Dialog A is the parent dialog, With a button click Dialog B is opened.  I am passing the parent dialog to Dialog B.  Then I am getting the array from A.

I know that they are better ways, I just want to know how bad of practice is it to do it this way?

Looking for your input
0
Comment
Question by:jkteater
  • 5
  • 2
8 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 50 total points
ID: 38787552
I had my doubts when I read "circular reference".
But what you meant isn't really "circular reference"

If - in dialog B - you need to access the array of dialog A, imo, there's nothing wrong with what you do.

But one could have questions about *why* you need to access that array in Dialog B.
Is it really needed? Or could a better design eleminate that need?
0
 

Author Comment

by:jkteater
ID: 38787593
Basically because I am creating a new array in dialog B by combining 2 arrays.  One from Dialog A and the other in Dialog B.  

I thought it was a OK way to do it, but I had peer to strongly disagree.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 38787654
If you only need the array, you could of course also only pass that one instead of your complete DialogA.

>> I had peer to strongly disagree
And what was his/hers argumentation to not do it that way? (Maybe we overlooked something)
0
 

Author Comment

by:jkteater
ID: 38787749
They claim that each Dialog should be self dependent.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Expert Comment

by:krakatoa
ID: 38787768
You might want to consider programming to an interface, and in your implementing class, create the various Dialog objects you need there.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 38787844
>> They claim that each Dialog should be self dependent.
I see. They mean, they shouldn't "know" each other; i.e. Dialog B shouldn't have any "knowledge" about the (existance of) class DialogA.
Well, then don't pass a DialogA parameter to DialogB 's constructor, but just an array.
Done. No dependencies.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 38787886
Or alternatively - the comment of krakatoa inspired me ;-) - do it like this:

public interface ArrayOwner {
     Array getArray();
}

Open in new window


with
public DialogA implements ArrayOwner {

    public Array getArray() {
          return b; // being your array inside DialogA
    }

}

Open in new window

and
public class DialogB {

    private arrayOwner;

    public DialogB(ArrayOwner arrayOwner, etc, etc) {
         this.arrayOwner = arrayOwner;
         ...
    } 


    Array c = arrayOwner.getArray();
} 

Open in new window


This way the constructor of DialogB accepts an ArrayOwner as parameter.
Which can be an instance of DialogA, but also every other class instance implementing ArrayOwner. That way DialogB does not depend on DialogA, just on interface ArrayOwner.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 38787892
Thanx 4 axxepting
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now