0

I'm trying to make an application in javafx but i'm having trouble with choosing the right variable types. I'm rather new to Object oriented programming and the application would have to display a bunch of variables of personnes in a tableView. Afterwards i will do alot of calculations with these variables. The problem is that i started with normal variables like strings, int's and arrays. It worked fine but now that i'm trying to display them in a table view it gets very complicated and i'm not sure if i used the right types. I've seen some other people use Stringproperties and other funky stuff but then i would have to change all my code. Are these types better to use and why? And is there a general rule to follow when your building your main data class so that you can avoid these problems? Are there important things you should take into account when building your main structure?

Here is some code of how i did it right now:

//this class would be used to store the choices of every leader. 
//It then can be used to make the best possible distribution for next year.
public class Leiding {  //leiding => scouts leader in dutch ;)
private static final AtomicInteger count = new AtomicInteger(0);
private int id = 0;
private String naam;
private Leiding[] voorkeurleiding = new Leiding[3]; //3 prefeerd other leaders (from 1 till 3)
private Leiding[] afkeurleiding = new Leiding[3]; //3 disliked leaders
private Tak[] voorkeurTak = new Tak[3];
private Leiding relatie;
private int score;

public Leiding(String naam, Leiding relatie){
    this.naam = naam;
    this.relatie= relatie;
    this.id = count.incrementAndGet();

}
public Leiding(String naam){
    this.naam = naam;
    this.id = count.incrementAndGet();

}
public String getNaam(){return naam;}

public void setNaam(String naam){this.naam = naam;}

public boolean checkNaam(String naam){ return this.naam == naam;}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public int getScore() {
    return score;
}

...
}

Sorry if this question is too broad but i found it hard to find a cleary answer to this and i have a feeling that these things are related.

kobey
  • 139
  • 1
  • 12
  • 3
    The "funky stuff" like `SimpleStringProperty` is to get updates in your data reflected in the tableview automagically, or the other way around. They are `ObservableValue`s https://docs.oracle.com/javase/8/javafx/api/javafx/beans/value/ObservableValue.html – Arjan Jun 07 '16 at 19:23
  • This question is way to broad for this site. The thing what @Arjan says is absolutely true, but you shall first read a bit about object oriented programming at all, at least what is a class and an object and what are primitives. And + 1 for automagically :) – DVarga Jun 07 '16 at 19:36
  • 1
    and your "checknaam" method probably does not do what you want it to do, please read http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java – Arjan Jun 07 '16 at 19:55

0 Answers0