top | item 6444453

(no title)

FuzzyDunlop | 12 years ago

It doesn't feel like it's enterprise enough to be realistic.

    class TwoBaconRashersInsideTwoSlicesOfBreadFactory {
      
      /* Make a sandwich
       * <p>
       * Construct a foodstuff consisting of two slices 
       * of bread with two slices of bacon.
       * @return TwoBaconRashersInsideTwoSlicesOfBread a sandwich
       */
      Public TwoBaconRashersInsideTwoSlicesOfBread getSandwich () {
       BaconRasherFactory pig = new BaconRasherFactory();

       BaconRasherInstance bacon1 = pig.getBaconRasher();
       BaconRasherInstance bacon2 = pig.getBaconRasher();


       SliceOfBreadFactory loaf = new SliceOfBreadFactory();
       
       SliceOfBread bread1 = loaf.getSliceOfBread();
       SliceOfBread bread2 = loaf.getSliceOfBread();

       return new TwoBaconRashersInsideTwoSlicesOfBread(bread1, bacon1, bacon2, bread2); 
    }
Or something... trying to do Enterprise Java is hard.

discuss

order

pkorzeniewski|12 years ago

Not enterprise enough, it doesn't implement any interfaces nor extends any generic classes, there also should be some try/catch blocks (what if the bacon isn't fried enough?) and of course several unit tests to guarantee the highest quality sandwich ;)

JonnieCache|12 years ago

There isn't even any XML. Not enterprise at all, by definition.

Uchikoma|12 years ago

Language bashing is what characterizes our industry.

I have the dream that one day we will recognize languages as the tool they are and be mature enough to chose tools by utility and not by hype, hipness or pop culture and see there benefits and limitations.

icebraining|12 years ago

I have the dream that one day we will recognize languages as the tool they are

We do. They're just terrible tools. Do you think other industries don't criticize their tools? Hell, they have full magazines and reports reviewing and grading them.

The idea that all languages/tools are created equal and just have different use cases is nonsense.

Bootvis|12 years ago

He is not bashing Java per SE but a special kind of Java: Enterprise Java and IMO that deserves a bashing on general principle. Enterprise Java just never seems appropriate.

talmand|12 years ago

But how will some define their superiority? By not using semi-colons?

astral303|12 years ago

Hmm... how about...

@Service public class SandwichFactoryImpl implements SandwichFactory {

	    @Autowired
	    public EmptySandwichFactory emptySandwichFactory;

	    @Autowired
	    public FoodComponentFactoryFactory foodComponentFactoryFactory;

	    @Override
	    public Sandwich makeSandwich(Collection<FoodComponentDescription> foodComponentDescriptions) {

	        Sandwich sandwich = emptySandwichFactory.newSandwich();

	        for (FoodComponentDescription foodComponentDescription : foodComponentDescriptions) {
	            FoodComponentFactory foodFactory = foodComponentFactoryFactory.getFactory(foodComponentDescription.getType());

	            for (int i = 0; i < foodComponentDescription.getQuantity(); i++) {
	            	sandwich.addFood(foodFactory.create());
	            }
	        }
	        
	        return sandwich;
	    }

	    public SandwichDTO makeMyFavoriteSandwich() {
	        Collection<FoodComponentDescription> components = Lists.newArrayList();

	        components.add(new FoodComponentDescription(FoodType.BREAD, 1));
	        components.add(new FoodComponentDescription(FoodType.BACON, 2));
	        components.add(new FoodComponentDescription(FoodType.BREAD, 1));

	        return makeSandwich(components);
	    }

	}

FuzzyDunlop|12 years ago

This is much more inspired. I sort of feel sympathetic, because of the potential mental anguish you were likely to have incurred while writing it.

cgh|12 years ago

Your use of "new" implies those factories have no interfaces. Normally they would be injected.

pjmlp|12 years ago

Any language has hard time being enterprise.

That what the space station architects are there for.

vezzy-fnord|12 years ago

Make the comment into Javadoc, add some more modifiers, increase the method names and I think you're well on your way.