What use are EJBs

后端 未结 7 1298
一生所求
一生所求 2020-12-02 20:23

I\'m currently learning Jave-EE, having plenty of C++ experience and having learned Java SE. I don\'t understand the purpose of Enterprise Java Beans; can someone clarify th

7条回答
  •  鱼传尺愫
    2020-12-02 21:05

    Use of Java EE does not automatically imply a anemic domain model, just as you can write code in say java what does not make good use of best practices doesn't mean it's not possible in java. I believe Martin Fowler's point was J2EE (note the use of J2EE and not Java EE) pretty much enforced operation of logic and data. Using POJO based entities allows data and behaviour to modelled appropriately. The "business logic" in your EJBs typically orchestrates application of business logic but more often than not does not actually perform it, it is usually a very thin wrapper.

    EJBs thus form your Service API, you need this whichever platform/framework you are using, you need to have something you can physically invoke, it is an entry point. Whether you are implementing using spring, web services etc... You need a service layer, there is nothing stopping this been implemented in Java EE. A rather contrived example

    @Stateless
    public SomeServiceImpl implements SomeService
        someServiceMethod() {
           delegate.doSomething();
        }
    }
    
    public SomeServiceDelegate implements SomeService
        someServiceMethod() {
           modelObject.doSomething();
        }
    }
    

    I'm not going into the reasons to prefer EJBs over any other technology, just wanting to point out that using them doesn't mean your implementation can't use best practice.

提交回复
热议问题