I have been developing in Java specifically over 5 years now.
Now always when I start writing a new class or code, I start with defining the properties of my class. So I will need to hit eclipse generate getter and setter every time to my dissapoint. And that is cleaner code and much more understandable in the end.
But I enjoy thinking abstract and using of OOP and generics. So there is either an specific reason people need to use Java primitives or we can just create a class like this in Java to always have an getter and setter and still be within the normal use of Java class members :
public class Property<Type> implements Getter<Type>,Setter<Type>{
protected Type value;
public Property() {
}
@Override
public <T extends Type> void set(T value) {
this.value = value;
}
@Override
public Type get() {
return value;
}
public String toString() {
return value.toString();
}
}
You can still use modifiers to limit the access to the variables you define. You will still use the same variable declaration as in:
Class test{
private Property<Number> priv_floatProperty = new Property<Float>();
protected Property<Number> prot_floatProperty = new Property<Float>();
public Property<Number> publ_floatProperty = new Property<Float>();
}
Just wanted to ask this question to see what other people think about this code and writing your classes in this way. I really hope I can get some feedback about this code and the theory of class design in Java,