Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

GUI + encapsulation

$
0
0
Yo.
Suppose i have a View class in an MVC application and i have the private JTextField. Now i also have the Controller class that is responsible for user inputs. Relationship between classes is Controller depends on View ---> Controller has a View.

Spoiler


Now, the question is: should the View class expose the TextField or just provide methods to manipulate it.

Approach 1 :

class View{

private TextField field;
public TextField getField(){return field;}



Approach 2 :
class View{
private TextField field;
public String geText(){return field.getText();}
public void clearText(){...}
etc..



Is it a question of preferance of is one more encouraged than the other one.
THanks.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>