J
Jordi
Hello
I have a doubt about how to write classes.
I have written something like this:
-----------
/*
* Data.java
*/
import java.io.Serializable;
package com.me.myPackage;
// abstract class to create others based on this
abstract class Data implements Serializable {
// variables
private String aData;
String getData(String data) {
return aData;
}
void setData(String data) {
this.aData = data;
}
}
-------------
So when I write a class that extends the class Data, I must set those
variables with:
setData("blabla");
These methods may only be used by classes in its package
I avoided using public methods or public variables for this class and
its subclasses to increase security.
Is this a good point, or not?
I saw some people do things like this but I don't know if I am doing
well. Most people used private variables but public methods.
Thanks for any oppinion.
Jordi
I have a doubt about how to write classes.
I have written something like this:
-----------
/*
* Data.java
*/
import java.io.Serializable;
package com.me.myPackage;
// abstract class to create others based on this
abstract class Data implements Serializable {
// variables
private String aData;
String getData(String data) {
return aData;
}
void setData(String data) {
this.aData = data;
}
}
-------------
So when I write a class that extends the class Data, I must set those
variables with:
setData("blabla");
These methods may only be used by classes in its package
I avoided using public methods or public variables for this class and
its subclasses to increase security.
Is this a good point, or not?
I saw some people do things like this but I don't know if I am doing
well. Most people used private variables but public methods.
Thanks for any oppinion.
Jordi