• Create Account

### #Actualilreh

Posted 08 May 2014 - 12:50 PM

For 1) the equivalent of POJO is POD - where you make a struct where all the members are public, and all the members are either primitive types, raw pointers, or other POD types.

If every member has a getter/setter, then they may as well just be public.

Although they can be used equivalently there are differences. If you add a set-method you can include error-handling and polymorphism which can help you maintain correct behavior.

For example:
you have a class Player and a member called health. If you use a set-method you can also implement something like:

void Player::setHealth(int x) {
if (x < (maxhealth /4) && x > 0) {
Player::yell("I need a medic!");
}
if (x <= 0) {
}
health = x;
}



Of course right now you would probably implement stuff like this in a method like "registerDamage" and this would probably make more sense but if you design a set-method from begin with you are more flexible to changes. You could also check for a negative number and add a line to your log that something went wrong.

Another advantage of using set-methods is that you can easily implement conceptional future changes. For example if you decide later on that max health should be 99 instead of originally planned 9999, you simply have to add a /100 here and it's all set. Otherwise you'd have to go through your code and modify every occurence where the variable was changed from the outside.

### #6ilreh

Posted 08 May 2014 - 12:45 PM

For 1) the equivalent of POJO is POD - where you make a struct where all the members are public, and all the members are either primitive types, raw pointers, or other POD types.

If every member has a getter/setter, then they may as well just be public.

Although they can be used equivalently there are differences. If you add a set-method you can include error-handling and polymorphism which can help you maintain correct behavior.

For example:
you have a class Player and a variable called health. If you use a set-function you can also implement something like:

void Player::setHealth(int x) {
if (x < (maxhealth /4) && x > 0) {
Player::yell("I need a medic!");
}
if (x <= 0) {
}
health = x;
}



Another advantage of using set-methods is that you can easily implement future changes. For example if you decide later on that max health should be 99 instead of originally planned 9999, you simply have to add a /100 here and it's all set. Otherwise you'd have to go through your code and modify every occurence where the variable was changed from the outside.

### #5ilreh

Posted 08 May 2014 - 12:27 PM

For 1) the equivalent of POJO is POD - where you make a struct where all the members are public, and all the members are either primitive types, raw pointers, or other POD types.

If every member has a getter/setter, then they may as well just be public.

Although they can be used equivalently there are differences. If you add a set-method you can include error-handling and polymorphism which can help you maintain correct behavior.

For example:
you have a class Player and a variable called health. If you use a set-function you can also implement something like:

void Player::setHealth(int x) {
if (x < (maxhealth /4)) {
Player::yell("I need a medic!");
}
else if (x <= 0) {
}
health = x;
}



Another advantage of using set-methods is that you can easily implement future changes. For example if you decide later on that max health should be 99 instead of originally planned 9999, you simply have to add a /100 here and it's all set. Otherwise you'd have to go through your code and modify every occurence where the variable was changed from the outside.

### #4ilreh

Posted 08 May 2014 - 12:26 PM

For 1) the equivalent of POJO is POD - where you make a struct where all the members are public, and all the members are either primitive types, raw pointers, or other POD types.

If every member has a getter/setter, then they may as well just be public.

Although they can be used equivalently there are differences. If you add a set-method you can include error-handling and polymorphism which can help you maintain correct behavior.

For example:
you have a class player and a variable called hp. If you use a set-function you can also implement something like:

void Player::setHealth(int x) {
if (x < (maxhealth /4)) {
Player::yell("I need a medic!");
}
else if (x <= 0) {
}
health = x;
}



Another advantage of using set-methods is that you can easily implement future changes. For example if you decide later on that max health should be 99 instead of originally planned 9999, you simply have to add a /100 here and it's all set. Otherwise you'd have to go through your code and modify every occurence where the variable was changed from the outside.

### #3ilreh

Posted 08 May 2014 - 12:25 PM

For 1) the equivalent of POJO is POD - where you make a struct where all the members are public, and all the members are either primitive types, raw pointers, or other POD types.

If every member has a getter/setter, then they may as well just be public.

Although they can be used equivalently there are differences. If you add a set-method you can include error-handling and polymorphism which can help you maintain correct behavior.

For example:
you have a class player and a variable called hp. If you use a set-function you can also implement something like:

void Player::setHealth(x) {
if (x < (maxhealth /4)) {
Player::yell("I need a medic!");
}
else if (x <= 0) {
}
health = x;
}



Another advantage of using set-methods is that you can easily implement future changes. For example if you decide later on that max health should be 99 instead of originally planned 9999, you simply have to add a /100 here and it's all set. Otherwise you'd have to go through your code and modify every occurence where the variable was changed from the outside.

### #2ilreh

Posted 08 May 2014 - 12:17 PM

For 1) the equivalent of POJO is POD - where you make a struct where all the members are public, and all the members are either primitive types, raw pointers, or other POD types.

If every member has a getter/setter, then they may as well just be public.

Although they can be used equivalently there are differences. If you add a set-method you can include error-handling and polymorphism which can help you maintain correct behavior.

For example:
you have a class player and a variable called hp. If you use a set-function you can also implement something like:

void setHealth(x) {
if (x < (player.maxhealth /4)) {
player.yell("I need a medic!");
}
else if (x <= 0) {