Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Lewis Evans   on May 05 In Java Category.

  
Question Answered By: Jackson Bouchard   on May 05

The correct OO way to do this is to use the
Bridge Design Pattern.<br><br>I will describe the design
pattern and then explain WHY this is the best OO way to
do this.<br><br>You create a class  with a method
that accepts the two objects as parameters. Each class
should have get/set methods for each of the variables.
The bridge class would get the variables  one by one
from object A and pass  it to Object B.<br><br>This
sounds like a lot of work, but what this does is
"uncouple" Class A and Class B. Class A doesn't even have to
know about the existance of Class B and vice versa.
The "bridge" class is the object that
knows.<br><br>That way, if Class A changes, Class B doesn't have to
change. If class B goes away, class A doesn't have to
change. And the bridge only passes those pieces of
information that are needed to be passed. One could also have
Class A and Class B implement an interface which has
those methods describing the variables which need to be
passed.<br><br>While this is not the most efficient method, it is one
that helps in the maintaince, "reusablitiy" and
encapsulation of each class.<br><br>Hope this
helps.<br><br>Stephen McConnell<br>http://www.crosslogic.com

Share: 

 

This Question has 9 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on passing variables Or get search suggestion and latest updates.


Tagged: