Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Programming Practice - Circular Reference between Dialog Classes

Posted on 2013-01-17
8
Medium Priority
?
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 200 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

Author Comment

by:jkteater
ID: 38787749
They claim that each Dialog should be self dependent.
0
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

688 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