Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Java:
- Класс билдера:
- public class RecipeBuilder
- {
- List<Ingredient> _ingredients;
- public void addIngredient(String name, Integer quantity)
- {
- Ingredient i = new Ingredient(name, quantity);
- _ingrediends.add(i);
- }
- }
- Используем билдер:
- public class Omelette
- {
- public Recipe build()
- {
- RecipeBuilder builder = new RecipeBuilder();
- builder.addIngredient("Eggs", 3);
- builder.addIngredient("Bacon", 1);
- }
- }
- Если бы в Java был classEval/instanceEval, как в Руби - то можно было бы написать так (псевдокод):
- omelette = new Lambda() {
- addIngredient("Eggs", 3);
- addIngredient("Bacon", 1);
- }
- builder = new RecipeBuilder();
- builder.instanceEval(omelette);
Add Comment
Please, Sign In to add comment