Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Java OO Kata 30/04/17
public interface IEntity {
}
public interface IWithName {
public String getName();
public void setName(String name);
}
public interface INamedEntity extends IEntity, IWithName {
}
public interface IOperations<T> {
public T findOne(String id);
public List<T> findAll();
public T create(T resource);
public void update(T resource);
}
public interface IService<T> extends IOperations<T> {
public List<T> findInIds(List<String> ids);
}
public abstract class AbstractService<T> implements IService<T>{
public T findOne(String id) { return null; }
public List<T> findAll() { return null; }
public T create(T resource) { return null;}
public void update(T resource) {}
}
@Service
public class PipeServiceImpl extends AbstractService<Pipe>{
@Override
public Pipe findOne(String id) {
return null;
}
@Override
public List<Pipe> findAll() {
List<Pipe> pipes = new ArrayList<>();
Pipe pipe = new Pipe();
pipe.setName("Ruth");
pipes.add(pipe);
return pipes;
}
@Override
public Pipe create(Pipe resource) {
return null;
}
@Override
public void update(Pipe resource) {
}
@Override
public List<Pipe> findInIds(List<String> ids) {
return null;
}
}
public class Pipe implements INamedEntity {
private String name;
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
}
@Controller
@RequestMapping(value = "/pipe")
public class PipeController {
@Autowired
private IService pipeService;
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public String findAll(){
List<Pipe> results = pipeService.findAll();
return Integer.toString(results.size());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment