S
Sameer
When we create a class in java we use several variables for
internal functioning of the class. The procedures of the class may
also contain local variables.
We introduce variables as we need it.
But how many of these variables be treated as fields of the class?
Do we have to decide a particular variable is going to be a field and
may be accessed from other classes?
For example in creating a GUI for an application we need to
define variables like
private JMenuBar menuBar;
private JMenu menuFile, menuLookAndFeel;
private JMenuItem menuItemExit, menuItemAbout;
public JLabel statusBar;
public JPanel contentPanel;
and they are generally declared as fields of the class.
But they do not fit in the role of fields of the class as we have
defined them for GUI creation only and a menu may not be
accessed externally.
Are there any guidelines in designing fields of the class?
How to differentiate between a field and an ordinary variables?
-Sameer
internal functioning of the class. The procedures of the class may
also contain local variables.
We introduce variables as we need it.
But how many of these variables be treated as fields of the class?
Do we have to decide a particular variable is going to be a field and
may be accessed from other classes?
For example in creating a GUI for an application we need to
define variables like
private JMenuBar menuBar;
private JMenu menuFile, menuLookAndFeel;
private JMenuItem menuItemExit, menuItemAbout;
public JLabel statusBar;
public JPanel contentPanel;
and they are generally declared as fields of the class.
But they do not fit in the role of fields of the class as we have
defined them for GUI creation only and a menu may not be
accessed externally.
Are there any guidelines in designing fields of the class?
How to differentiate between a field and an ordinary variables?
-Sameer