Design question about when to use inner classes for models

This is a general design question about when to use inner classes or separate classes when dealing with table models and such. Typically I'd want to have everything related to a table within one classes, but looking at some tutorials that teach how to add a button to a table I'm finding that you have to implement quite a sophisticated tablemodel which, if nothing else, is somewhat unweildy to put as an inner class.
The tutorial I'm following in particular is this one:
http://www.devx.com/getHelpOn/10MinuteSolution/20425
I was just wondering if somebody can give me their personal opinion as to when they would place that abstracttablemodel into a separate class and when they would just have it as an inner class. I guess re-usability is one consideration, but just wanted to get some good design suggestions.

It's funny that you mention that because I was comparing how the example I linked to above creates a usable button in the table and how you implemented it in another thread where you used a ButtonColumn object. I was trying to compare both implementations, but being a newbie at this, they seemed entirely different from each other. The way I understand it with the example above is that it creates a TableRenderer which should be able to render any component object, then it sets the defaultRenderer to the default and JButton.Class' renderer to that custom renderer. I don't totally understand your design in the thread
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=680674
quite yet, but it's implemented in quite a bit different way. Like I was saying the buttonClass that you created seem to be creating an object of which function I don't quite see. It looks more like a method, but I'm still trying to see how you did it, since it obviously worked.
Man adding a button to a table is much more difficult than I imagined.
Message was edited by:
deadseasquirrels

Similar Messages

  • Help,about why we use inner class?

    Hi,
    when i read "java Tutorial"
    i found there is one chapter about inner class .
    i copy it down as follow.
    the context is about there is a class Stack, and this class want to implement some function of interface Iterator,but as the book said
    we should not let class Stack implement the Iterator directly, we should add a inner class inside the Stack .
    i know it's very import ,but i still can not understand the reason why add a inner class here.
    hope somebody can explain it a little more for me or give an example.
    thank in advance!
    Iterator defines the interface for stepping once through the elements within an ordered set in order. You use it like this:
    while (hasNext()) {
    next();
    The Stack class itself should not implement the Iterator interface, because of certain limitations imposed by the API of the Iterator interface: two separate objects could not enumerate the items in the Stack concurrently, because there's no way of knowing who's calling the next method; the enumeration could not be restarted, because the Iterator interface doesn't have methods to support that; and the enumeration could be invoked only once, because the Iterator interface doesn't have methods for going back to the beginning. Instead, a helper class should do the work for Stack.
    The helper class must have access to the Stack's elements and also must be able to access them directly because the Stack's public interface supports only LIFO access. This is where inner classes come in.
    Here's a Stack implementation that defines a helper class, called StackIterator, for enumerating the stack's elements:
    public class Stack {
    private Object[] items;
    //code for Stack's methods and constructors
    not shown
    public Iterator iterator() {
    return new StackIterator();
    class StackIterator implements Iterator {
    int currentItem = items.size() - 1;
    public boolean hasNext() {
    public Object next() {
    public void remove() {
    or you can visit here
    http://java.sun.com/docs/books/tutorial/java/javaOO/innerclasses.html

    the context is about there is a class Stack, and this
    class want to implement some function of interface
    Iterator,but as the book said
    we should not let class Stack implement the Iterator
    directly, we should add a inner class inside the
    Stack .Simply because the implementation of the Iterator is nobody's business. By declaring it to be a private inner clss, nobody will ever know about it and only see the Iterator interface.

  • Please give me the information when to use inner classes in applications

    HI,
    please give me when to use the innerclasses

    > HI,
    please give me when to use the innerclasses
    Use them when you want to create a class within another class.
    Now gimme all 'er Dukes!!!

  • Question about when to use EJB

    Hello All,
    Right now, I am tasked with taking data out of the database and storing it on the mid-tier. We will be storing this static data in an XML file. We were hoping to read it in when starting the server and then persisting the data for the life of the server. Is this a good time to user EJB? All I have seen is examples using a database. We would like to take the database hit out of the equation when it comes to retrieving this data, but would also like to avoid parsing the XML doc every time someone logs in to the application. Is EJB a good answer here, or is it overkill?

    If this is for use as a read-only dictionary for supporting an EJB application, by all means.
    But to use EJB just to do this - I think that would be overkill.
    A singleton would do the job fine - especially if the XML doesn't change - actually even if it does that doesn't matter.

  • When will we use inner class

    hi
    when will we use inner class?

    JosAH basically already wrote this, but another way
    to say the same thing is this. If you are writing a
    class and you find it would be handy to have another
    class for that class to use, you can either write a
    separate class for each, or you can embed one in the
    other, making it an inner class. One advantage of an
    inner class is that you can meet a set of
    specifications by not having an extra class. It also
    makes more sense to have an inner class if it's
    something that's not useful on its own.I think it is the second most important advantage of inner class
    (First is: you can access the private members of the outer class)

  • Hi when i use treeMap class and if i exit the program

    hi
    hi when i use treeMap class and if i exit the program,
    what will happen? the information that i put in the treeMap will be disappear??
    if it is like that,,how am i able to retrieve my data...when i restart my program..
    once i put ID as key and put my customer information,
    in it, after exit my program,, and i can't find
    my customers by their ID,,,,,,,,,how can,,i solve it......

    what will happen? the information that i put in the
    treeMap will be disappear??Yes. Of course. If you want data to hang around you have to tell the computer. If you want anything to happen you have to tell the computer.
    if it is like that,,how am i able to retrieve my
    data...when i restart my program..Tada! Tell the computer. Your simplest option is to use Serialization.
    Before exiting your program, serialize your TreeMap to disk. After starting your program serialize your TreeMap from disk.
    First stop should be your text book to learn what Serialization is and how it works, then try to write some code, then ask us to help with any problems.
    Dave.

  • When to use abstract class compared to interface

    hi
    can some one plase advise me when to use abstract class compared to interface?
    Example will be appreciated...

    So an abstract class can carry implementation. This can be used to formulate a rule of thumb as to when to use it over an interface.
    If you have a so called type specialization relationship between the subtypes and the supertype then they're likely to benefit from shared implementation provided by the supertype, so use class (abstract or concrete) extension in this case. Type specialization is when the supertype represents a general concept like Fruit and the subtypes are specialized forms of that like Apple and Banana.
    Another common kind of relationship is called type expansion. In this case the subtypes are unlikely to have any use of implementation provided by the supertype, so use interface implementation. Type expansion is when the supertype represents a specific character the subtypes take on. For example Apple and Bicycle ure unrelated in the type specialization sense but still can share a common character like Comparable. The subtypes have been expanded to include the supertype character, namely the ability to be compared.

  • Question about openning files using SDK 10.

    I have written a Plug-In for SDK 9 that works wonderfully. One of the functions is for the user to be able to page (Next/Previous) between PDF files on our server. This functionality now longer works without crashing Acrobat 10. All I am doing is creating the URL path to the next/previous PDF, creating a CustomFileSys with the path and calling AVDocOpenFromFile.
    Does this no longer work with Acrobat 10 SDK?
    Thanks!

    Should work fine, AFAIK.
    For this level of issue, I would open a formal support request with developer support.
    From: Adobe Forums <[email protected]<mailto:[email protected]>>
    Reply-To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
    Date: Mon, 10 Oct 2011 08:51:08 -0700
    To: Leonard Rosenthol <[email protected]<mailto:[email protected]>>
    Subject: Question about openning files using SDK 10.
    Question about openning files using SDK 10.
    created by Greggars<http://forums.adobe.com/people/Greggars> in Acrobat SDK - View the full discussion<http://forums.adobe.com/message/3963065#3963065

  • Passing argument to, when using one class for multiple assets

    I had a class that I was passing a simple argument to like so:
    var quiz_1_2:CaseStudyQuiz = new CaseStudyQuiz(2);
    addChild(quiz_1_2);
    I now would like to use this class for multiple MCs in my library. I thought I could let Flash create a class for each of them and specifying the CaseStudyQuiz class as the Base class. When I do that, I get the following error:
    1136: Incorrect number of arguments.  Expected 0.
    Obviously this is because the class created by flash does not except an argument. Does that mean, I would have to create a seperate class for each of the movies that use that class? And if so, what would I have to do in that class for it to except the parameter and pass it on to my base class?
    Thank you very much for any help with this!!!

    use the super() function and pass your parameter.  but you still might get a runtime error but i don't think that will cause a problem.

  • One question about Pricing and Conditions puzzle me for a long time!

    One question about Pricing and Conditions puzzle me for a long time.I take one example to explain my question:
    1-First,my sale order use pricing procedure RVAA01.
    2-Next,the pricing procedure RVAA01 have some condition type,such as EK01(Actual Costs),PR00(Price)....,and so on.
    3-Next,the condition type PR00 define the Access Sequences PR00 as it's Access Sequences.
    4-Next,the Access Sequences PR00 have some Condition tables,such as:
         table 118 : "Empties" Prices (Material-Dependent)
         table 5 : Customer/Material
         table 6 : Price List Type/Currency/Material
         table 4 : Material
    5-Next,I need to maintain Condition tables's Records.Such as the table 5(Customer/Material).I guess the sap would supply one screen for me to input the data of table 5.At this screen,the sap would ask me to select one table,such as table 5.When I select the table 5,the sap would go to the screen to let me input the data of table 5.But when I use the T-CODE VK31 or VK32 to maintain Condition tables's Record,I found it's total different from my guess:
    A-First,I can not found one place for me to open the table,such as table 5,to let me input the data?
    B-Second,For example,when I select the VK31->Discounts/Surcharges->By Customer/Material,the sap show the grid view at the right side.At the each line of the grid view,you need to select the Condition Type at the first field.And this make me confused very much.Why the sap need me to select one Condition Type but not the Condition table?To the normal logic,it ought not to select Condition table but not the Condition Type!
    Dear all,I'm a new one in sd.May be this is a very stupid question.But it did puzzle me for a long time.If any one can  explain this question in detail and let me understand the concept,I will appreciate him/her very much.Thank you.

    Hi,
    You said that you are using the T.codes VK31 or VK32.
    These transaction codes are used to enter condition records for standard condition types. As you can see a grid left side having all the standard condition types like price, discounts, taxes, frieghts.
    Pl check using T.code VK11 OR VK12 (change mode)
    Here you can enter the required condition type, in the intial screen. (like PR00, MWST, K004, K005 .....etc)
    After giving the condition type, press enter or click on Combinations icon on top of the screen. Then you can see all the condition tables which you maintained for that condition type. Like as you said table 118, table 5, table 6 and table 4.
    You can select any table and press enter, then you can go into the screen in which you have all the field cataglogues you maintained for that table. For example you selected combination of Customer/Material (table 5) then after you press enter then you can see customer field on top, and material fields.
    You can give all the required values and save the conditon record.
    Hope this is clear.
    REWARD IF HELPFUL.
    Regards,
    praveen

  • Is anyone else having email problems such as apps exiting in the middle of an email? It may be a wireless issue. I use First Class for work and yahoo email for personal. I will be in the middle of typing a long email and the app just quits, all data lost.

    Is anyone else having email problems such as apps exiting in the middle of an email? It may be a wireless issue. I use First Class for work and yahoo email for personal. I will be in the middle of typing a long email and the app just quits, all data lost.

    Have you tried restarting or resetting your iPad?
    Restart: Press On/Off button until the Slide to Power Off slider appears, select Slide to Power Off and, after the iPad shuts down, then press the On/Off button until the Apple logo appears.
    Reset: Press the Home and On/Off buttons at the same time and hold them until the Apple logo appears (about 10 seconds). Ignore the "Slide to power off"

  • Problem creating inner class for JTable panel in a class for an application

    i want to create an inner class for a database application development.
    but there is occuring exceptions & errors.i want to retrieve data & enter data also from many tables in a database.i want an urgent help for this plz.

    http://forum.java.sun.com/thread.jsp?forum=57&thread=271752
    See this thread, please.

  • How to use multiple classes for each form

    Hi,
    I have created two forms using screen painter and now i want to use different classes for these two forms .
    I have declared the Sbo Connection in main class i.e. Set Application ,Connection Context() but while connecting to other classes
    for executing the code for that form SAP is not connected to that class.How to use multiple classes functionality i don't able to
    do that.Please provide some sample codes for that as it will be more helpful for me to understand.
    Thanks & Regards,
    Amit

    Hi Amit,
    In fact, its more advisable to use separate classes for every form that you use.  Have one common class, say, for eg., clsMain.cs which has all the connection and connectivity to other classes, wherein, the menu event and item event of this main class, will just be calling the menu / item event of other classes.
    The individual functionality of the child classes will be called from the item / menu event of the respective classes.
    Item event in clsMain.cs will be as below.
    private void oApplication_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)
                SAPbouiCOM.Form oForm;
                BubbleEvent = true;
                try
                    if ((pVal.FormTypeEx == "My_Form1Type") && (pVal.EventType != SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD))
                        oForm = oApplication.Forms.GetForm("My_FormType", pVal.FormTypeCount);
                        NameSpace.Repots.ClsForm1.ClsForm1_ItemEvent(oApplication, oCompany, oForm, ref pVal, ref BubbleEvent);
                    if ((pVal.FormTypeEx == "My_Form2Type") && (pVal.EventType != SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD))
                        oForm = oApplication.Forms.GetForm("My_FormType", pVal.FormTypeCount);
                        NameSpace.Repots.ClsForm1.ClsForm2_ItemEvent(oApplication, oCompany, oForm, ref pVal, ref BubbleEvent);
    Now, in the individual classes, you can have their respective item events, which will be called from the main class, and the respective functionalities will occur.
    Hope this helps.
    Regards,
    Satish.

  • When to use Nested Class/Inner Classes ?

    I am not very clear, when to use nested/inner classes..
    The scenario is :-
    class ABC
    //ABC need to store multiple instance of class XYZ
    class XYZ
    int member1;
    int member2;
    One approach is
    class ABC
    class XYZ
    //vector of class XYZ instances is stored in class-ABC
    or another approach is Class XYZ can be in separate JAVA file.
    Query:-
    1) Is there any difference between nested or Inner class...or are they same?
    2) When should they be used....Is it good to use in above scenario.
    3) What are the disadvtanges/advantages of using the Nested
    class.

    Query:-
    1) Is there any difference between nested or Inner
    class...or are they same?I really don't get it. Yes there is a difference between having an inner class, and a class in a separate file, but a nested class is an inner class.
    2) When should they be used....Is it good to use in
    above scenario.To write an inner class is a design decision. Do other classes need to know about the class XYZ or not? Do the XYZ class need to know about the inner working of the ABC class? How complex is the XYZ class etc.
    >
    3) What are the disadvtanges/advantages of using the
    Nested
    class.See above.
    /Kaj

  • Help: Factory Class using Inner Class and Private Constructor?

    The situation is as follows:
    I want a GamesCollection class that instantiates Game objects by looking up the information needed from a database. I would like to use Game outside of GamesCollection, but only have it instantiated by GamesCollection to ensure the game actually exist. Each Game object is linked to a database record. If a Game object exist, it must also exist in the database. Game objects can never be removed from the database.
    I thought about making the Game object an inner class of GamesCollection, but this means that Game class constructor is still visible outside. So what if I made Game constructor private? Well, now I can't create Game objects without a static method inside Game class (static Object factory).
    Basically what I need is a constructor for the inner Game class accessible to GamesCollection, but not to the rest of the world (including packages). Is there a way to do this?

    leesiulung wrote:
    As a second look, I was initially confused about your first implementation, but it now makes more sense.
    Let me make sure I understand this:
    - the interface is needed to make the class accessible outside the outer classBetter: it is necessary to have a type that is accessible outside of GameCollection -- what else could be the return type of instance?
    - the instance() method is the object factory
    - the private modifier for the inner class is to prevent outside classes to instantiate this objectRight.
    However, is a private inner class accessible in the outer class? Try it and see.
    How does this affect private/public modifiers on inner classes?Take about five minutes and write a few tests. That should answer any questions you may have.
    How do instantiate a GameImpl object? This basically goes back to the first question.Filling out the initial solution:
    public interface Game {
        String method();
    public class GameCollection {
        private static  class GameImpl implements Game {
            public String method() {
                return "GameImpl";
        public Game instance() {
            return new GameImpl();
        public static void main(String[] args) {
            GameCollection app = new GameCollection();
            Game game = app.instance();
            System.out.println(game.method());
    }Even if you were not interested in controlling game creation, defining interfaces for key concepts like Game is always going to be a good idea. Consider how you will write testing code, for example. How will you mock Game?

Maybe you are looking for

  • MissingResourceException Error when Starting Application

    I am getting the following error when starting an Enterprise application in weblogic 10.3.6: .MissingResourceException: Can't find bundle for base name resources.Messages, locale en A snippet from my faces-config.xml file:      <application>      <lo

  • "LabVIEW PDA - Palm OS Hardware?"

    I'd like to get some feedback on what Palm OS PDA's are being used in conjunction with the LabVIEW PDA software. I've been tasked with creating a very compact application for monitoring a system, and we're interested in doing this through a Palm PDA

  • E-90 HELP HELP HELP PLEASE!!!!

    Hey guys! I have problems opening attachments in my hotmail with my E-90, anyone can help????? Can you tell me how to open them?. I have finally got into the hotmail account but cannot see what they send me!!! Also the Real player it is not working n

  • Wie können Fotos in RAW in das Lightroom Mobile inportiert werden?

    ich verwende ein iPad und habe eine Sony Alpha 7 . Fotos die via Sny Mobile inportiert werden, werden in jpg gewandelt. gibt es eine Input Möglichkeit in Lightroom Mobile? besten dank

  • How to import sony analog tapes for editing on Macbook?

    Macbook does not have a firewire port. How can I import analog tapes into Macbook for editing?