I'd like to know the answer to this simple question.
When I create an entity object and I want to restrict a setting of an attribute (for example I don't want to allow anyone to set an integer value less then 1 to an attribute), should I implement it in the setter of this attribute or should I check this restriction latter in a class that handles these objects ? Generally, can I implement getters and setters however I want as long as my getters return and setters set attributes ?
I know there are some rules (code conventions) in java, so I don't want to break any of them.
Thanks in advance, hope that my question is clear enough and sorry for any grammar mistakes I might have made :/ .
Entity Rules provides an alternative method of triggering Rules. Instead of adding entity related events to Reaction Rules you are able to select which special Rules components will fire when different entity events are triggered.
What is creation of a business entity? Creation of a business entity is the legal or procedural steps that one must undertake to bring the business entity into existence. There is a general dichotomy in the process or steps required to form a business entity.
Yes getters/setters are useful for that.
for example:
public void setAge(int age){
if(age < 0){
throw new IllegalArgumentException("Invalid age : " + age);
//or if you don't want to throw an exception you can handle it otherways too
}
}
You can also use Java-EE's Bean Validators for this
public class Person{
@Min(value = 0)
@Max(value = 99)
private Integer age;
//some other code
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With