Design question: Communication between objects

Hi all,
Just interested in some opinions from your experience. If you have two components, say two GUI components which are repesented by two separate classes, and you need to have these classes communicate in a relatively small way, how would you do it?
What I've done is passed a reference of the second object to the first.
I guess I'm wondering whether this would be considered a reasonable design, or should there be some in-between class which manages the communication between objects.
For a more concrete example: I have a main class (with my main() )which is a JFrame, and this frame has a split panel. I want the left and right sides to communicate with each other. Should I handle the communication through my main class, or should I "couple" the two classes upon initialization and let them do their communication independent of the my main class?
Thanks for any opinions or comments.

>
When the user selects a node on the JTree, I want to
populate a particular ComboBox on the right based on
what the user selected in the tree. Or I may just
re-initialize the entire right component based on the
selected node on the JTree.
I guess I was wondering whether I should "marry" the
JTree and the JPanel class, and let them do their
communicating when needed, or whether I should manage
the communucations through the JFrame class.
For example, say I use the JFrame as a "message
manager". The JFrame class will listen for events
from the JTree on the left side, and then send the
appropriate information to the right side. This way
the JTree class and the JPanel class would have no
knowledge of each other. They are glued together
through my JFrame.
Thanks for your opinions.
Then you must register a selection listener with the JTree with addTreeSelectionListener this listener has a reference to the combo. The listener can be a new class (inner class or anonymous) used only for this purpose.
Bye.

Similar Messages

  • Maximizing communication between objects.

    Hi,
    I have a question concerning communication between objects. Particularly I want to learn to maximize communication between objects. Obviously there are several ways of increasing communication between objects, unfortunately I only really understand one methodology, which is as follows:
    For example:
    If I were to create an object called GUI of class UserInterFace, like so
    class UserInterface extends JFrame
      private variable1;
      private variable2;
      UserInterface()
        setBounds(x,y,width,height);
        setVisible(true);
    }I could then create an object called fileOps of class FileOperations and pass the entire GUI object into the constructor of the fileOps class, as follows:
    class FileOperations
      private FileReader input;
      private FileWriter output;
      private UserInterface GUI;
      FileOperations(UserInterface GUI)  //GUI object introduced.
        this.GUI = GUI;
    }By following the code fragments above it becomes obvious that I can establish communications between the fileOps object and the GUI object. With code similar to the above; fileOps will be able to access all of the accessor and mutator methods within object GUI. Using the above methodology always requires making all variables private and accompanying those variables with public methods (thus preserving encapsulation).
    If anybody can suggest any other methodologies for increasing communication between objects they will be greatly appreicated. Of interest to me is how one can go about ensuring complete two way communication between objects, my example above is rather one sided (fileOps can see GUI, but not vice versa). Obviously the instantiation of objects must occur in some procedural sequence, I want to know how to capitilize on this. Suggestions to read a particular book will be appreciated, however suggestions born from peoples experiences are most desired. Thanks.
    Regards
    David

    Rommie and Rajesh,
    Thank you both kindly for sharing your time and valuable knowledge. As I have only been programming with Java for a year part time (as one section of a Computer Systems Diploma) I consider myself to be a beginner in programming terms. I want to do really well with Java as quickly as possible and you have both helped me tremendously.
    Rommie the methodology that you have passed onto me is great, thankyou so much, I feel like a new section of Java has completely opened to me. I will be using the third "reference" class methodology from everyday now on.
    Rajesh your words are encouraging, and I will be reading up on Hierarchy and Aggregation immediately. When you said "Before using either, decide on the existence of the object, its intended functionalities e.t.c. ...", could you please explain with an example as to where Hierarchy is desirable and where Aggregation is desirable.
    Please feel free to e-mail me with further suggestions if you come up with something else that aids in the communication between objects.
    E-mail: [email protected]
    Thanks again.
    Regards
    David

  • Design question: methods returning objects

    I have a general design question. When, in general (and why), should you have a method alter an object via it's methods but not return the object as opposed to doing the same operation in a method and then return it.
    Consider the two below methods which do basically the same thing. When is one desireable over the other, and why?
    Cheers--
    public void setMyIntField(SomeObject pObj){
    pObj.setSomeInt(5);
    public SomeObject setMyIntField(SomeObject pObj){
    pObj.setSomeInt(5);
    return pObj;
    }

    Let me give a better example:
    class FruitWorker{
      private void someMethod(){
        HashMap myCitrus = new HashMap();
        HashMap myTropicals = new Hashmap();
        // use my no return obj method
        addFruitProps1(myCitrus,
                       "tartnes",
                       new FruitProperty("very!" ));
        // use my return object method
        myTropicals =  addFruitProps2(myCitrus,
                                      "sweetness",
                                       new FruitProperty("little bit" ));
      }// end method
      private void addFruitProperties1(HashMap pFruitProps,
                                       String pProp
                                       FruitProperty pVal){
        pFruitProps.add( pProp,pVal);
      }// end method
      private HashMap addFruitProperties2(HashMap pFruitProps,
                                       String pProp
                                       FruitProperty pVal){
        pFruitProps.add( pProp,pVal);
        return pFruitProps;
      }// end method
    }// end class

  • Import Oracle Designer model dependencies between objects

    Hello,
    I am using the Oracle Designer model import to fill Data Modeler. There are some views which have dependencies on each other, resulting that views which depend on other views are incomplete.
    Is there a way to rerun the import again in the same relational model, since the import utility now opens a new relational model again.
    Is there a kind of logging where you can find these kind of errors?
    Best regards,
    Joop

    Thanks Phillip, but I was actually referring to the version level of the Designer repository itself, not the database instance in which it resides. I seem to remember that you could not upgrade your Designer repository without also upgrading the Oracle Designer client as well; hence my question about compatibility between SQL Developer Data Modeler and various Repository versions.

  • Design Question: Creating One Object Type From Multiple Inputs

    Hi,
    I'm attempting to expand my brain a bit and come up with a more elegant solution to a design I created a few years ago. In simple terms, I have a data object (Request) which can be created based on data in a text file or from data previously persisted in a database record using the Request object and associated DAO. Typically, the text file is initiating a "new" Request object to be persisted, and reading from the database is done to update or view previously submitted Request objects. Note that I have no ability to change the original input method of the text file.
    In my original design I basically lumped everything into the Request class using multiple constructors which made for a messy jumble and a very long class. Different parsing routines were needed when data was read from the file vs. reading it from the database. I was considering refactoring the code to use a factory class but this doesn't seem to follow the typical Abstract Factory or Factory Method design patterns. In my design I keep ending up with something like:
    public class RequestFactory {
        public Request createRequestFromFile(File file) {...build up the request object...}
        public Request createRequestFromDbRecord(int recordId) {...build up the request object...}
    }And I would change the constructor in my Request class to private and remove all of the parsing and construction methods.
    Now, I can definitely make this work but I'm not sure I'm really doing much except taking the creation garbage (there's a lot of parsing of multiple-value fields that needs to be done) out of the actual Request class. So my question is basically, do I have a better approach I'm not seeing or is this type of factory "appropriate"? I mean, would someone come along later and look at my code and think I was crazy? I'm still trying to wrap my head around some ways to use factories in my own projects so I'm probably not thinking clearly.
    Thanks!
    Pablo

    Thanks for the feedback. About your suggestions on dealing with the different loading methods, I think that's where I keep getting disconnected, at least as far as using an abstract factory is concerned.
    Extending your example code a bit using option one, I would guess I end up with something like this:
    public interface RequestFactory {
      Request createRequest(RequestSource source) throws RequestCreationException;
    public class DatabaseRequestFactory implements RequestFactory {
      public Request createRequest(RequestSource source) throws RequestCreationException {
        // do some stuff
    }The part I can't figure out is how to define the RequestSource (or RequestId in your example). It would seem that if I'm going to define member variables in RequestSource like SourceFile or RecordId it would be just as correct to skip the interface and just use two concrete classes like this:
    public class FileRequestFactory {
      Request createRequest(File file) throws RequestCreationException {
        // process file and create request
    public class DatabaseRequestFactory {
      public Request createRequest(int recordId) throws RequestCreationException {
        // load record and create request
    }I guess where I keep stumbling is a) the value of the interface and b) if I do use an interface, how to have a generic object passed to createRequest() that can refer to either a file location or a record ID. This concept is pretty clear when the creation requirements for each concrete factory are the same, but when the construction uses such disparate data sources for creation I can't seem to wrap my head around the differences.
    Your third suggestion is probably the easiest for me to understand but it seems like it would be a bit contrived. In the end it may make the most sense if I am going to go with that type of approach since I still don't really understand how to implement the first two options.
    Thanks again for your input.
    Pablo
    Edited by: Pablo_Vadear on Dec 15, 2009 6:11 AM

  • Adobe Livecycle Designer Question (relationships between nested tables)

    Hi,
    I am currently working on a PDF document using nested tables.
    I have already created the relationships between the nested tables in the context area.
    However, I do not know how to create the same relationships between the nested tables in the hierarchy (layout.)
    Any and all help will be greatly appreciated.
    Thank You.

    Hello John,
    We define data in the context area only. The defined data in the context area will be available in the Layout area in the hierachy model(Data View tab).
    In the Layout tab, we just need to design the form. 
    Hope I am clear. Please let us know if you want more details.
    Thanks
    Ramakrishna

  • ASA IPSEC VPN Design Question; ARP Between ASA

    I"ve a requirement to put two ASA between two sites. The second site has hosts within the same network as the first site (conflict of fundamental routing principles). Can you put an ASA inline between the router and distribution switch at each site, setup an IPSEC VPN and not have issue? I thought we could have the distro switch terminate in the DMZ interface setup as a layer 2 interface in a vlan with a vlan int in the same network as the vlan int on the ASA DMZ interface on the ASA at the other site. Will this work? I guess the biggest concern is how to get layer 2 (arp) to work so hosts/servers can find each other between buildings and not get dropped on a layer 3 interface that doesn't see the distant network on a different egress interface.
    Thanks!
    Matt

    Matt,
    AFAIK - what you are describing is layer 2 tunneling, providing layer 2 networks from two speperate locations.
    The only way I am aware of how to provide this - does NOT invlove ASA's or VPN's suing layer 3. You could do this over MPLS or a transparent layer 2 pt-pt circuit.
    Perhaps another netpro has done this or knows how - I did hear of someone bridging thru a GRE tunnel, not sure if that is a viable option or actually works.
    HTH>

  • How would i design the relationship between "question", "subquestion", and "answer"

    Hi all. Consider the following scenario:
    Scenario:
    A Question has an Answer, but some Questions have Subquestions. For example:
    1. Define the following terms: (Question)
    a) Object (1 marks) (Subquestion)
    An instance of a class. (Answer)
    b) ...
    2. Differentiate between a constructor and a destructor (2 marks)
    (Question)
    A constructor constructs while a destructor destroys.
    (Answer)
    Question:
    I want to model Questions, Subquestion, and Answer as Entities with relationships/associations, preferably binary relationships as i feel ternary relationships will be problematic while programming. Any suggestion on how i would
    go about this?
    There is never infinite resources.
    For the Question Entity, a question has the attributes "QuestionPhrase <String>", "Diagram<Binary>", and "Marks
    <Decimal>".
    For the SubQuestion Entity, a subquestion has the attributes "SubQuestionPhrase <String>", "Diagram<Binary>", and "Marks <Decimal>".
    For the Answer Entity, an answer has attributes, "AnswerPhrase<String>", "Diagram <Binary>"

    Yes. I am in .Net. I sure do hope i did not ask in the wrong forum. :-|
    Hi KCWamuti,
    If you need to design the relationship between Question table and Answer table in SQL Server, as Uri’s and Visakh’s posts, you can create the foreign key to establish relationship between tables, and use join in query to get your desired result. For more
    information about JOIN in SQL Server, please review this article:
    Different Types of SQL Joins.
    However, if you need to model Questions, Subquestion, and Answer as Entities in .Net, then the issue regards data platform development. I suggest you post the question in the Data Platform Development forums at
    http://social.msdn.microsoft.com/Forums/en-US/home?category=dataplatformdev . It is appropriate and more experts will assist you.
    Thanks,
    Lydia Zhang

  • Communication between javascript and Objective-c in iOS.

    We wanted to have a communication between javascript and objective c code. We have already tried the below approach.
    To load fake URLs in JS and append a string which will be used as parameter to the Objective-C code and parse that URL in this delegate method:
    -(BOOL)webView(UIWebView *)webView shouldStartLoadWithRequest(NSURLRequest *)request navigationType(UIWebViewNavigationType)navigationType
    Then send the return value by calling the native method stringByEvaluatingJavaScriptFromString again with parameter callID.
    But we wanted to access Objective class object in Javascript code so that we can call it's methods from javascript code using this object.Android supports this behaviour using addJavaScriptInterface method in webview. Is it possible to have the similar approach in IOS? If not what is the best approach possible to acheive this? If we could achieve similar behaviour then we don't need to change the Jacascript code and will be reused. Please suggest the best possible solution.
    Regards,
    Karthik M.

    https://developer.apple.com/library/mac/documentation/AppleApplications/Conceptu al/SafariJSProgTopics/Tasks/ObjCFromJavaScript.html

  • Method design question...and passing object as parameter to webserice

    I am new to webservice...one design question
    i am writing a webservice to check whether a user is valid user or not. The users are categorized as Member, Admin and Professional. For each user type I have to hit different data source to verify.
    I can get this user type as parameter. What is the best approach to define the method?
    Having one single method �isValidUser � and all the client web service can always call this method and provide user type or should I define method for each type like isValidMember, isValidAdmin ?
    One more thing...in future the requirement may change for professional to have more required field in that case the parameter need to have more attribute. But on client side not much change if I have a single isValidUser method...all they have to do is pass additional values
    isValidUser(String username, String usertype, String[] userAttributes){
    if usertype == member
    call member code
    else if usertype = professional
    call professional code
    else if usertype = admin
    call admin code
    else
    throw error
    or
    isValidMember(String username, String[] userAttributes){
    call member code
    One last question, can the parameter be passed as object in web service like USER object.

    First of all, here is my code
    CREATE OR REPLACE
    TYPE USERCONTEXT AS OBJECT
    user_login varchar2,
    user_id integer,
    CONSTRUCTOR FUNCTION USERCONTEXT (
    P_LOGIN IN INTEGER
    P_ID_ID IN INTEGER
    ) RETURN SELF AS RESULT
    Either your type wont be compiled or this is not the real code..

  • Communicating between seperate flex objects

    Hello,
    I want to have an invisible flex object in the menu frame of
    my website and have a certain page, displayed in the other frame,
    in which there would be another flex control with all the necessary
    controls to control the invisible flex object. Is this possbile and
    how should I go about this?
    Thank you.

    yeah!!! it is possible, you can use the ExternallInterface
    class and some javascript functions for communicating between
    them.

  • XI Configuration Design questions with multi-mapping message mapping object

    Hello,
    I'm having trouble designing a particular scenario for multi-mapping.  Currently i'm working with a Vendor create and change.  BPM is not being used.
    This is what i need:
    I need a CREMDM04 to turn into one or multiple ADRMAS/CREMAS IDocs and potentially a CLFMAS IDoc based on the values in the inbound CREMDM04 IDoc.
    This is what i currently have:
    A CREMDM04 inbound idoc is multi-mapped to a CREMDM03 (1...9999), another CREMDM03 (0...9999), and a CLFMAS01 (0...9999).  At a minimum only the first CREMDM03 IDoc will be created and at a maximum all three will be created.  The parameters on creating the second CREMDM03 IDoc and the CLFMAS01 IDoc are based on the values in the inbound CREMDM04 IDoc, whereas the first CREMDM03 IDoc will always be created and the values will just be converted/mapped from the inbound CREMDM04 IDoc.  This multi-mapping is currently set-up via a graphical message map and works successfully in the test-tab of the mapping object.  It has a main message and has sub-messages which are the IDocs.  I’m mapping the CREMDM04 to a CREMDM03 to then map it through an ABAP-Class and then to an XSL where the CREMDM03 inbound structure is expected to split into ADRMAS and CREMAS Outbound IDocs for Vendor Create/Change in the remote R/3 systems.
    After the graphical map we have a necessary ABAP Class call that calls a BAPI to the remote system.  This ABAP Class must come after the graphical map since the parameter for the BAPI is based on a converted value from the graphical multi-map.
    After the ABAP Class call there is finally an XSL message split the CREMDM IDoc into an ADRMAS and CREMAS IDoc.  There need to be two interface mappings (one per ADRMAS and CREMAS) since the ABAP classes and XSLs are specific to the ADRMAS and CREMAS.
    The CLFMAS IDoc can go directly to the remote system, but since it’s within this one multi-map, I’m not sure if is possible?  I’m not sure if it will fail once it tries entering the XSL mapping (this is the standard CREMDM message split offered from SAP).
    There are three interface mapping scenarios I can think of, but cannot get to work:
    CREMDM04 to ADRMAS02
    CREMDM04 to CREMAS03
    CREMDM04 to CLFMAS01
    Currently I have the Interface Mapping structured as follows:  (I cannot get this to activate as it appears it does not work)
    Multi-Mapping ==> ABAP Class Call ==> Standard XSL Message Split
    How should i design the interface mapping objects and the configuration objects for this scenario?
    Any help is appreciated and I definitely will reward points (no need to include it in your response).

    Hi,
    I suggest you may use multiple steps interface mapping. It's composited with 3 message mappings as step by step.
    Mapping 1: One to one mapping. For the output schema, use a composition schema which includes those 3 IDOCs you want.
    Mappign 2: ABAP Mapping. I am not sure the ABAP class you mentioned is an ABAP mapping or not. If it does, That's ok. If not,
    call that ABAP class in your ABAP mapping and do corresponding change for your message. Return back the same structure as output.
    Mapping 3: One to multiple mapping to split the message.
    So basically as interface mapping, it's one to multiple mapping. And internally, you have 3 steps to realize the mapping.
    And as my experience, for both one to multiple message mapping & multiple steps interface mapping, it works well in my project. And
    in ID, you have to configure it via "advance" function in receiver determination or interface determination.
    Let me know if any confusion.
    Thanks
    Nick

  • Design question: Link data between JFrames

    Dear all,
    I have a design question. I have this form in a JFrame where you can set an icon as a property. To achieve this, I have a "Set" button on the form which will open a new window with all the available icons. When you click an icon, I want the "icon" frame to be closed and the selected icon to be send to the original form. This is the way I do it now:
    Interface :
    public interface IconUpdate
    public void updateIcon(Icon icon);
    }Main frame with the "Set" button:
    public class Test extends JFrame implements IconUpdate, ActionListener
        private Icon icon = null;
        public Test()
            // add button and actionlistener and that kind of stuff
        public void actionPerformed(ActionEvent e)
            if(e.getSource() == btnSetIcon)
                new IconFrame(this);
        public void updateIcon(Icon icon)
            this.icon = icon;
    }The Icon frame:
    public class IconFrame extends JFrame implements ActionListener
        IconUpdate parent = null;
        public IconFrame(IconUpdate parent)
            this.parent = parent;
            // Initialize table,"Pick" button etc.
        public void actionPerformed(ActionEvent e)
            if(e.getSource() == btnPick)
                parent.updateIcon((Icon)list.getSelectedValue());
                this.dispose();
    }Maybe I made some spelling faults, but this is the way I implement it. Now my question is: is there another way to achieve my goal? If I have to create an interface for every "popup choose dialog" in my program, I have to create many of them. I know using a combobox in the main frame is an option, but I just want to use it this way. Can anyone tell me how I can rewrite this code to make it better / more professional?
    Tx in advance!!!
    Peter

    I can think of a couple options:
    1) Let IconFrame's constructor accept a Test parameter, instead of creating an interface.
    2) Make IconFrame into a modal dialog & have it store the user's selection in a variable. Then when you show the dialog, your action listener will block until the user selects an icon. Then you can call "getSelectedIcon()" to retrieve his/her selection. This would be much like the JOptionPane.showXXX() methods, and probably the cleaner solution.

  • Can Designer generate ADF Entity Objects, View Objects and Apps Module ?

    Hi all,
    On what way can Designer integrate with JDeveloper (+ ADF) ?
    Can Designer generate ADF Entity Objects, View Objects and Apps Module ?
    Thank you for your help,
    xtanto

    Designer itself has no direct integration with JDeveloper. However, there are three options. First of all, you can get a JDeveloper extension (download this separately) that lets you create a Connection to a Designer repository. From that Connection you can find modules that you defined in Designer and generate Entity and View objects for the tables and columns that you used in those modules, and an Application Module. It does not create JSPs or other user interface objects.
    Another option is to buy JHeadstart from Oracle. This contains a set of code generators and ADF extensions that include an ability to get information from a Designer repository. JHeadstart works fine for non-Designer users too, but was built by the same people who wrote Designer Headstart - they know the repository API intimately.
    The third option is to download Oracle Designer Extension Builder (ODEB) which was just recently made available. This is a product of a collaboration between Designer users from the Oracle Development Tools Users Group (ODTUG) and Oracle to extend the capabilities of Designer with user written tools and utilities. You could use ODEB to write your own generators for ADF Business Components. Or you could wait and see if someone else in the user community does this. I hope that you or whoever does such a generator will be willing to share it with us all.

  • Communication between two portlets - Java Portlet JSR168

    Communication between two portlets
    Hi All,
    i want to be question how do communication between two portlets. Exam:
    I have 2 portlets in a portal together: a Menu portlet & a Content portlet, now i want when i click to an link of portlet Menu then my Content portlet will get param from link that.
    i'm develop by Oracle Jdeveloper tool & OracleAS 10g.
    Thank a lot !

    Hello,
    I assume you are not using Weblogic Portal, correct? If you are using Weblogic Portal, you could use events to communicate between two JSR168 portlets, but this only works in Weblogic Portal.
    If you are not using Weblogic Portal, the only way to communicate between two JSR 168 portlets is to put an attribute in the session in one portlet, and retrieve it from the session in the other portlet. For example, to set a value in your Menu portlet, given a javax.portlet.PortletRequest variable "request", and an object you want to send to the content portlet in the variable "menuChoice":
    javax.portlet.PortletSession session = request.getPortletSession(true);
    session.setAttribute("menuChoice", menuChoice, javax.portlet.PortletSession.APPLICATION_SCOPE);
    Then, in your content portlet to retrieve the value of the menuChoice variable you would do this:
    javax.portlet.PortletSession session = request.getPortletSession(true);
    Object menuChoice = session.retAttribute("menuChoice", javax.portlet.PortletSession.APPLICATION_SCOPE);
    Kevin

Maybe you are looking for

  • Please add support for JPEG Exchangeable Image File Format (EXIF)

    It seems that now Adobe® Illustrator® can export only to the JPEG File Interchange Format (JFIF). We should have an option to produce the JPEG Exchangeable image file format (EXIF) as well (just like Photoshop does!). Why this is so important to me?

  • How to resize photos for web pages

    Can photos be resized within iPhoto to be used on a web site?  If not what is the best program to do this to keep good quality photos but have a fast reloading time.

  • Re: How do I set Adobe as the default over Nuance?

    ..I am running Adobe Reader XI and Nuance Advanced PDF. I want to designate Adobe as the default and use Nuance whenever I open it. Currently, Nuance opens for everything automatically and blocks Adobe. I know I am overlooking something simple. Thank

  • Replication of tracks creating broken DC

    Hi Experts, I am new to webdynpro java. I want to use a track from one server. But since i cannot directly use that track we have replicated the track in other server from where I can import it with the help of basis team. There were no broken DC in

  • ORA-04052: error occurred when looking up remote object SYS.DBMS_SNAPSHOT

    Hello everyone, When I tried to create a materialized view with refresh fast mode, I encountered following error message. The MV log has been created on my_table like this: create materialized view log on my_table tablespace data3 with rowid, sequenc