to extend or not

Discussion in 'Java' started by -, Mar 29, 2005.

  1. -

    - Guest

    which is the preferred style?

    public class App {

    private JFrame frame;

    public App() {
    frame = new JFrame();
    }
    }

    or

    public class AppFrame extends JFrame {

    public AppFrame() {
    }
    }
     
    -, Mar 29, 2005
    #1
    1. Advertising

  2. -

    R.F. Pels Guest

    - wrote:

    > public class App {
    >
    > private JFrame frame;
    >
    > public class AppFrame extends JFrame {


    Those two are not the same. You really need to read a book on Object
    Oriented Programming.

    --
    Ruurd
    ..o.
    ...o
    ooo
     
    R.F. Pels, Mar 29, 2005
    #2
    1. Advertising

  3. -

    Peter Kirk Guest

    "R.F. Pels" <> skrev i en meddelelse
    news:d2b6ue$cka$1.ov.home.nl...
    > - wrote:
    >
    > > public class App {
    > >
    > > private JFrame frame;
    > >
    > > public class AppFrame extends JFrame {

    >
    > Those two are not the same. You really need to read a book on Object
    > Oriented Programming.


    It's hard to know whether or not "-" knows that these are not equivalent. My
    guess is that he does know they are different, and is asking "what is
    'best'" - that is, composition or inheritance.

    I don't have a definitive answer, but there are plenty of hits on Google
    when searching for "java composition inheritance".

    Peter
     
    Peter Kirk, Mar 29, 2005
    #3
  4. -

    Ulf_N Guest

    - skrev:
    > which is the preferred style?
    >
    > public class App {
    >
    > private JFrame frame;
    >
    > public App() {
    > frame = new JFrame();
    > }
    > }
    >
    > or
    >
    > public class AppFrame extends JFrame {
    >
    > public AppFrame() {
    > }
    > }


    Ask yourself: Is your class first and foremost a JFrame (your own
    version of a JFrame, overriding JFrame methods etc.), or does your class
    just happen to use a JFrame (as a gui window, for instance)? In most
    cases you probably use JFrame (composition) rather than modify it
    (inheritance). It all depends on what your class is and does... /ulf
     
    Ulf_N, Mar 29, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yuriy

    How to Extend Session time

    Yuriy, Oct 16, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    9,759
    Bratislav Jevtic
    Oct 17, 2003
  2. David T
    Replies:
    3
    Views:
    369
    Alf P. Steinbach
    Mar 8, 2009
  3. Gavin Kistner
    Replies:
    5
    Views:
    170
    Robert Klemme
    Oct 23, 2004
  4. Daniel Berger
    Replies:
    3
    Views:
    128
    Daniel Berger
    Oct 30, 2004
  5. Replies:
    3
    Views:
    127
Loading...

Share This Page