Swing best practice - private modifier vs. many parameters

Dear Experts,
I have a comboBox that has a customized editor and has KeyListener that responds to several keyPressed and keyTyped. The comboBox is used in two different JFrame, say JFrame frmA and JFrame frmB.
Since the KeyListener changes the state of 8 other components in frmA, I have two options:
Option 1:
- Coding the comboBox in separate class and pass all components as parameters. I will have around 10 parameters, but the components can be made private to frmA or frmB.
Option 2:
- Coding the comboBox in separate class and pass the instance of the caller (frmA or frmB), so that the comboBox can change the state of the other components in frmA or frmB according to its caller. However, the components must not be private and should be able to be accessed by the comboBox class.
My questions:
1. I have not implemented option 2, so that I have not proved that it will work. Will it work?
2. Which option will be more efficient and require less cpu time? If it is the same, which option is the best practice?
3. Is there any other option that is better than these two options?
Thanks for your advice,
Patrick

Option 2:
- Coding the comboBox in separate class and pass the instance of the caller (frmA or frmB), so that the comboBox can change the state of the other components in frmA or frmB according to its caller. However, the components must not be private and should be able to be accessed by the comboBox class.
My questions:
1. I have not implemented option 2, so that I have not proved that it will work. Will it work?It doesn't stand in the long run. Doing so couples your specific ComboBox classes to all widgets that react to the ComboBox changes. If you happen to add a new button is either JFrame that should also be affected by the combo-box selection, you'll have to modify, and re-test, the ComboBox code. Moreover, if a new button was needed in one the JFrame but not the other, you'd have to introduce a special case in your combobox code.
Instead of the ComboBox's listeners invoke methods on each piloted widget, have them invoke one method (+selectionChanged(...)+) on these widget's common parent (not necessarily a graphical container, but an object that has (maybe indirect) references to each of the dependant widgets).
2. Which option will be more efficient and require less cpu time?I wouldn't mind.
In the graphical layer of an application, and unless the graphcial representation performs computations on the bitmap, any action is normally much quicker than business logic computation. Any counter-example is likely to be a bug in the UI implementation (such as, not observing Swing's threading rules), or a severe flaw in the design 'such as, having a hierrachy of several hunderd JComponents,...). Swing widgets are pretty reactive to genuine calls such as setEnabled(), setBackground(), setText(),...
If it is the same, which option is the best practice?Neither. Hardcoding relationships between widgets may be OK within a single, and single-purpose, form.
But if you want to code a reusable component thoug, design it for reuse (that is, the less it knows about how which context it is used in, the more contexts it can be used in).
In general, widgets that know each-other involve a quadratic number of references that accordingly impacts the code readability (and bug rate). This is the primary reason for introducing a Mediator pattern (of which my reply to 1 above is a degenerate form).
3. Is there any other option that is better than these two options?Yes. Look into the [+Mediator+|http://en.wikipedia.org/wiki/Mediator_pattern] pattern (the Wikipedia page is not compelling, but you'll easily find lots of resources on the Web).

Similar Messages

  • Request for any Best Practice document for configuring Service Parameters on CUCM 9.1.1

    Hi Team,
    Could you please send if you have any  Best Practice document for configuring Service Parameters on CUCM 9.1.1. That would really help.
    Thanks,
    Guru

    Hi
    There's no 'best practice' as such, but there are a few that I think should be default:
    Enabling CDR, On-Hook Pickup, CFwdAll Override... but really the settings are specific to the requirements of the deployment.
    Aaron

  • Best practice when modifying SAP Standard Development Component

    Hello Experts,
    What is best practice when modifying SAP Standard Development Component (Java Web Dynpro)? Iu2019m looking for the best method to do modifications to SAP Standard DC so that my changes will be kept (or need low maintenance) after a new service package (or EHP) is applied.
    Thanks,
    Kevin

    Hi,
      'How to use Busiess Packages in Enterprise Portal 6.0' is available in this link.
    http://help.sap.com/bp_epv260/EP_EN/documentation/How-to_Guides/misc/Using_Business_Packages.pdf
    Check out for the best practices.
    Regards,
    Harini S

  • Best practices to modify process chain

    Hi,
    What is the best practice to modify the  process chain whether in in the production or transport back to the dev.
    Does Query performing tuning setting should be done in production like read modes,cache settings.
    Thanks
    nikhil

    Hi Nikhil,
    The best practice to modify the process chains will be making the change in Development system and transporting to Quality and Production. But if you are making a simple change like changing the scheduling time ( change of scheduled date and time by editing the variant) you can do it directly in Production. But if you are adding new steps to process chain, it is better to make change in Dev and move it to Prod.
    Also once the change reach production you may need to open the chain in edit mode and activate it manually.
    It is a common issue for the process chains containing delta DTP, that the chain will be saved in modified (M)  version and not in active version by transports.
    The query read mode and cache settings, you can do it in Development and move it to production.
    But the pre-filling of cache using broadcaster settings can be done directly in production.
    Also creating of cube aggregates to improve query can be done directly in production rather than creating in development and transporting to Prod.
    Again, it depends on project, as in some projects they make changes directly in Prod, while in some projects changes in Prod are not allowed. I think it is better always start the changes in dev and move it to P.
    Hope it helps,
    Thanks,
    Vinod-

  • Best practice to modify OIM webApp.war in Weblogic (10g - 9102)

    I very generic question for OIM in Weblogic:
    If I'm doing any change(minor or major) in any of the JSP file in OIM xlWebApp.war, what is the best practice of moving it to production ?
    Thanks,

    Hi,
    Here the steps you should do:
    - unwar the xlWebApp.war file (through jar command)
    - Modify/add the jsp's.
    - War it again.
    - copy/replace that at XEL_HOME/webapp location.
    - if you had modified xml or properties file, copy that to DDTemplate/webapp
    - run patch_weblogic command.
    - restart server.
    You can also write a build script which will take OOTB xlWebApp.war and custom jsp's and will generate new xlWebApp.war.
    Once tested successfully in dev/QA env, you can check in code and new xlWebApp.war file in some subversion.
    In Production you can directly use this xlWebApp.war file and run patch command.
    Also look at this:
    Re: Help: OIM 10G Server With Weblogic
    Cheer$
    A..

  • Best practices for subcriptions of many servers

    Thinking of monitoring free space on my servers. Servers are 2003,2008,2012 (plus R2). Basing on
    http://fehse.ca/2013/07/disk-space-monitoringcommon-practices/ - need to make three monitors for each version of server. So, the best practice is to create there groups based on version
    condition. But we have many specialized servers (BizTalk, CRM, different application servers etc.) and want alert send to application admins. How can I implement such taks without creating a buch of groups based on application and override each monitor to
    each group?

    If you have multiple different teams, you will most likely need multiple different SCOM groups to organize your notifications and configure overrides against.  You could limit the number of groups you have to create by using the same group for both
    the override and the notification to the app team.  For example, if you are looking to customize thresholds for the Biztalk servers, you would create a SCOM group and add the various logical disk objects to that group.  When you create your threshold
    override, you will target that group of disk objects.  When you create your notification, you will scope the notification to the logical disk space monitor and this group of disk objects.  Beyond this there isn't much you can do to keep from creating
    a bunch of groups.  You may actually have multiple groups for the Biztalk team even, if they are utilizing multiple os'es for their servers because you should not combine disks from different os versions into the same group as your overrides will not
    work properly.

  • BGP Best Practice / Private-AS vs. Public-AS in the MPLS Core

    Dears,
    We have recently aquired a large network with ASR9K as Internet Gateways and non-Cisco devices in the MPLS Core.
    We would liike to know which is the best recommended solution to use Private MP-BGP AS in the MPLS Core or extend the IGW Public AS, knowing  that the IGW will be in a VRF and not the global routing table. Moreover, the clients of the MPLS Core have their own BGP Public AS and would need to connect to the MPLS Core to obtain internet services from the IGW.
    (Cust1)------EBGP------[VRF_Cust_1](MPLS CORE AS_2)[VRF_IGW]------EBGP-----(IGW AS_1) in the case of having a private BGP AS in the core
    (Cust1)------EBGP------[VRF_Cust_1](MPLS CORE AS_1)[VRF_IGW]------iBGP-----(IGW AS_1) in the case of having same public BGP AS in the core
    Waiting for your feedback and thoughts.
    Thanks,
    Michel.

    Michel,
    if your mpls core is also used for internet transit, then it is best to be a public AS.
    if not, then you can leave it be and remove the private AS at your border routers.
    If oyu are connecting multiple MPLS networks together to link L2 or L3 VPN services, I think it is easiest to have it all one AS, otherwise you end up with complex designs such as Carrier supporting Carrier (CSC) or Inter-AS option A (vrf lite), B (using vpnv4 at the inter AS gateay) or C (using vpnv4 at the interAS gateway with route reflectors in each AS peering with each other).
    regards
    xander
    Xander Thuijs CCIE #6775
    Principal Engineer 
    ASR9000, CRS, NCS6000 & IOS-XR

  • Need best practice: one application or many?

    We have a database and are going to build GUI using ApEx
    The question is:
    should we create many applications - one for every task (or group of tasks / user roles)
    or create one large application (hundreds of pages)
    Why?

    Greetings,
    I don't know much about the subject.
    But i can tell you two things.
    First you can create groups inside an applications so even having hundreds of pages you can still have them seperated by groups.
    Second in a large applications composed by several applications you can make a common login for all so you only need to login once. I have seen a thread about thsi recently.
    My opinion?
    One application is best...
    Because in a GUI you probably will have a lot of Javascript to make things smooth in the client side.
    Also Javascript code can and SHOULD be kept apart from the application, you should just link the file to the application template. I recomend prototype/scriptaculous for this because they are already used by APEX and are excelent with many examples in the web.
    Don't forget to assign points to those who help you! (Mark the thread Helpful/Correct)
    My Homepage
    Best Regards

  • Best practice question - elipsis or array parameters?

    When I design APIs I have the choice between something like
        public static void foo(String[] params)
            // do stuff
        }or
        public static void foo(String... params)
            // do stuff
        }If I have both declarations I get the following error (which I can understand):
    "cannot declare both foo(java.lang.String...) and foo(java.lang.String[]) in blablabla.Main
    public static void foo(String... params)"
    So I can use one or the other. The question is: What is "better"?
    The elipsis version (with ...) looks nicer because I don't have to build an array prior to calling foo if my params do come from separate sources and I can pass them both separately.

    But isn't this the same as a call to foo(null) if I would have used the array version?Depends on how you implemented your method. Example:
    public static void foo1(String[] params) {
      for(String param: params) {
        System.out.println(param.length());
    public static void foo2(String... params) {
      for(String param: params) {
        System.out.println(param.length());
    public static void main(String[] args) {
      foo1(null);
      foo2();
    }The call foo1(null) would fail for obvious reasons, whereas foo2() would be valid.
    Lesson: an empty array is different from a null array.
    However, is there any other consideration I should do - performance for instance? Forget about performance: ellipsis is just a convenient way to overload a method for the no-arg case, so use it if you have a no arg-case, else use the array version.

  • Best practice when deleting from different table simultainiously

    Greetings people,
    I have two tables joined with a foreign key contrraint. They are written at the same time to keep the constraint happy but I don't know the best way of deleting them as far as rowsets and datamodels are concerned. Are there "gotchas" like do I delete the row in the foreign key table first?
    I am reading thread:http://swforum.sun.com/jive/thread.jspa?forumID=123&threadID=49918
    and getting my head around it.
    Is there a tutorial which deals with this topic?
    I was wondering the best way to go.
    Many Thanks.
    Phil
    is there a "best practice" method for

    Without knowing many details about your specifics... I can suggest a few alternatives -
    You can definitely build coordinating the deletes into your application - you can automatically delete any FK related entries prior to deleting the master, or, refuse to delete the master until the user goes and explicitly deletes the children... just depends on how you want to manage it.
    Also in many databases you can build the cascading delete rules into your database tables themselves.... so that when you delete the master the deletes automatically cascade. I think this is something you typically declare when creating the FK constrataint (delete cascade and update cascade rules).
    hth,
    v

  • Database best practice: max number of columns

    I have two questions that I would appreciate comments on...
    We have a table titled TRANSACTION with 160 columns and a view titled TRANSACTIONS_VIEW with 233 columns in it. This was designed by someone a while ago. I am wondering if it is against best practice to have this many columns in a table? I have never before seen a table with this many columns in it and feel that there must be a way to split the data into multiple tables to make it more manageable.
    My second question is on partitions, the above table TRANSACTION is partitioned by manually specifying partitions with max values on the transaction date starting august 2008 through january 2010 at 1 month increments. Isn't it much better to specify automatic partitioning using the interval clause?

    kev374 wrote:
    thanks for the response, yes there are many columns that violate 3NF and that is why the column count is so high.
    Regarding the partition question, by better I meant by using "interval" the partitions could be created automatically at the specified interval instead of having to create them manually.The key is to understand the logic behind these tables and columns. Why it was designed like this, if it's business requirement then 200 some columns are not bad, if it's design flaw 20 columns could be too much. It's not necessarily always good to have strict 3NF design, sometime for various reason you can denormalize the tables to get better performance.
    As to partitioning Q, you have to do the rolling window (drop/add partition as time goes by) type of partitioning scheme manually so far.

  • Best practice regarding package-private or public classes

    Hello,
    If I was, for example, developing a library that client code would use and rely on, then I can see how I would design the library as a "module" contained in its own package,
    and I would certainly want to think carefully about what classes to expose to outside packages (using "public" as the class access modifier), as such classes would represent the
    exposed API. Any classes that are not part of the API would be made package-private (no access modifier). The package in which my library resides would thereby create an
    additional layer of encapsulation.
    However, thus far I've only developed small applications that reside in their own packages. There does not exist any "client code" in other packages that relies on the code I've
    written. In such a case, what is the best practice when I choose to make my classes public or package-private? Is it relevant?
    Thanks in advance!

    Jujubi wrote:
    ...However, thus far I've only developed small applications that reside in their own packages. There does not exist any "client code" in other packages that relies on the code I've
    written. In such a case, what is the best practice when I choose to make my classes public or package-private? Is it relevant?I've always gone by this rule of thumb: Do I want others using or is it appropriate for others to use my methodes. Are my methods "pure" and not containing package speicific coding. Can I guarentee that everything will be initialized correctly if the package is included in other projects.
    Basically--If I can be sure that the code will do what it is supposed to do and I've not "corrupted" the obvious meaning of the method, then I usually make it public--otherwise, the outside world, other packages, does not need to see it.

  • Best practice: parameters, reports and control flow

    I am developing an application that has a number of different reports, each of which has a combination of similar parameter LOVs.
    I defined the LOVs on page 0, with a corresponding DISPLAY hidden field for each one, with each set to conditional display if its DISPLAY=Y. I have a page process on each page with a standard block setting the appropriate _DISPLAY's to Y or N depending on whether they are needed on that page or not.
    It is becoming difficult to maintain, and I would prefer to have a single block of code that is called when entering all pages for the first time; where a CASE statement can switch on and off the various LOVs for each page by setting their correspondings _DISPLAY hiddens.
    I cannot find a clear answer for this in the forums; and I am not very clear if it is possible, or if it is the best practice.
    If anyone has any advice, please let me know!!
    Thanks
    Mark

    Hi Mark,
    One of the first points of best practice in Apex is that any non-trivial chunks of PL/SQL coding should be centralised in the database as stored code.
    In your case, your generic code would check the page that is being loaded and through a case statement, selectively set values to display the required fields for that page. One problem with this is that you still need to modify this procedure every time you add a new page.
    An alternative to this would be to do away with the _DISPLAY items and have the LOV items Condidtion type set to
    Current Page is Contained Within Expression 1 (Comma delimited list of pages)
    You then only need to list the pages the item is available for as a comma separated list in Expression 1.
    You could go even further by storing the display logic for each LOV item in tables in the database and make this completely dynamic, but this may be seen as overkill.
    Regards
    Andre

  • (Swing) Reading fields from other forms - Best practice

    Hi All,
    I have been learning Java and Swing through NetBeans (quite a cool way to do it). I would like some 'best-practice' advice please. Google and search on this forum are normally my friends, can't find anything relevant for this though. I have created an application that seems to be functional, all my navigation is through tabs.
    To make my app portable I have created a ?Settings? part. To save having another tab, I have basically copied the way NetBeans deals with opening the ?About Box? in its example, and have set-up fields in here. This essentially opens a JDialog with fields through an option in the menu.
    I figure the best way to store the data is in a simple text file, and have the application read the values on start-up? Then when somebody changes the fields and saves it just overwrites the text file with the new values. I am not sure how to best read these in though, I can?t find a way of reading direct from the JDialog (i.e. var.getText()) which makes sense as the JDialog will be closed.
    Will my best practice simply be writing a class which reads the file, then whenever I need a value just calling the class?
    Thanks a lot

    You should not be using preference files unless you really know what you are doing. This is one area of the very few areas of Java programming that can have lasting nasty negative affects on a computer that runs the code if done wrong.
    If you want the user to save preferences it is better to just use xml. The advantage of preference files is they can be used by multiple programs and are permanent even after the program is done running/deleted/writen-over/forgotten. The disadvantages of preference files is they can be used by multiple programs, are permanent even after the program is done running/deleted/writen-over/forgotten, can cause damage to your OS, may be seen as harmfull by add blockers and/or anti-virus software, may lead to conflicts with other software that uses similar naming schemes, and are pretty much unportable.
    You are going to be much better off in the long run learning XML and just saving them there, an added benefit of XML is if you screw something up and it causes your program to no longer run you can easily edit the xml by hand.
    JSG

  • How to set global parameters? (Best Practice?)

    Dear all,
    I've experience with Infor Performance Management tools, Qlikview and also SAP Business Objects Reporting. As for last week i'm new to Microsoft Reporting Services. In our current environemnt we're setting up a Report Structure on top of an Analysis Service
    Cube.
    Currently I'm creating various reports (which works fine) on the mentioned Analysis Service Cube.
    My current question is, if there is a best practice to create reports with global variables? We'll have a package of ~20 reports which all relate to the same data source. My approach is that i'll define the reports, but the global parameters like "Current
    year", "Last year" etc. should be defined on a global page. That's the way I would have done it in the other BI tools.
    How is this done best in MS Reporting Services? Should i add an additional flat SQL server source and put the values in some ref tables? Or script the global parameter?

    Hi Praveen G,
    this blog was one of the sources I already found.
    I was searching for the "official" way to set the default-workbook - without manipulating the tables programmaticaly (and possibly inconsistant).
    Best regards,
      Marco

Maybe you are looking for