Skip to content

Instantly share code, notes, and snippets.

@up1
Last active August 29, 2015 14:07
Show Gist options
  • Save up1/bb288d1e52945cba7220 to your computer and use it in GitHub Desktop.
Save up1/bb288d1e52945cba7220 to your computer and use it in GitHub Desktop.
Conditional Branch
class Data {
public String format(List<String> datas) {
StringBuilder result = new StringBuilder();
boolean first = true;
for(String data : datas) {
if(first) {
first = false;
} else {
result.append(", ");
}
result.append(data);
}
return result.toString();
}
}
class Employee {
private int _type;
static final int ENGINEER = 0;
static final int SALESMAN = 1;
static final int MANAGER = 2;
Employee (int type) {
_type = type;
}
int payAmount() {
switch (_type) {
case ENGINEER:
return _monthlySalary;
case SALESMAN:
return _monthlySalary + _commission;
case MANAGER:
return _monthlySalary + _bonus;
default:
throw new RuntimeException("Incorrect Employee");
}
}
}
class Example2 {
public void create(boolean flag) {
if(flag) {
//TODO
} else {
//TODO
}
}
}
class UserDAO {
public void create() {
if( data not found ) {
throw new DataNotFoundException();
}
}
}
class UserService {
public void createNewUser() {
User user = userDao.create();
if(user != null) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment