to extend or not

?

-

which is the preferred style?

public class App {

private JFrame frame;

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

or

public class AppFrame extends JFrame {

public AppFrame() {
}
}
 
R

R.F. Pels

- said:
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.
 
P

Peter Kirk

R.F. Pels said:
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
 
U

Ulf_N

- 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top