In the third model, the impression is similar to the one proposed by firebody or Archie (or it may not be clear). Simply put, this model combines the domain object and Business Object of the second model into one. So itemmanager is no longer needed. In this model, there are only three classes:
Item: Contains entity information and all business logic.
Itemdao: Persistent Dao Interface Class
Itemdaohibernateimpl: Dao interface implementation class
Because itemdao and itemdaohibernateimpl are identical to the above, they are omitted.
Java code
- Public class item implements serializable {
- // All attributes and the getter/setter method are omitted.
- Private Static itemdao;
- Public void setitemdao (itemdao) {This. itemdao = itemdao ;}
- Public static item loaditembyid (long ID ){
- Return (item) itemdao. loaditembyid (ID );
- }
- Public static collection findall (){
- Return (list) itemdao. findall ();
- }
- Public Bid placebid (User bidder, monetaryamount bidamount,
- Bid currentmaxbid, bid currentminbid)
- Throws businessexception {
- // Check highest bid (can also be a different strategy (pattern ))
- If (currentmaxbid! = NULL & currentmaxbid. getamount (). compareto (bidamount)> 0 ){
- Throw new businessexception ("bid too low .");
- }
- // Auction is active
- If (! State. Equals (itemstate. Active ))
- Throw new businessexception ("auction is not active yet .");
- // Auction still valid
- If (this. getenddate (). Before (new date ()))
- Throw new businessexception ("can't place new bid, auction already ended .");
- // Create new bid
- Bid newbid = new bid (bidamount, this, bidder );
- // Place bid for this item
- This. addbid (newbid );
- Itemdao. Update (this); // call Dao for explicit persistence
- Return newbid;
- }
- }
In this model, all business logic is in item, and transaction management is also implemented in item.