Pattern of domain object (3)

Source: Internet
Author: User

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
  1. Public class item implements serializable {
  2. // All attributes and the getter/setter method are omitted.
  3. Private Static itemdao;
  4. Public void setitemdao (itemdao) {This. itemdao = itemdao ;}
  5. Public static item loaditembyid (long ID ){
  6. Return (item) itemdao. loaditembyid (ID );
  7. }
  8. Public static collection findall (){
  9. Return (list) itemdao. findall ();
  10. }
  11. Public Bid placebid (User bidder, monetaryamount bidamount,
  12. Bid currentmaxbid, bid currentminbid)
  13. Throws businessexception {
  14. // Check highest bid (can also be a different strategy (pattern ))
  15. If (currentmaxbid! = NULL & currentmaxbid. getamount (). compareto (bidamount)> 0 ){
  16. Throw new businessexception ("bid too low .");
  17. }
  18. // Auction is active
  19. If (! State. Equals (itemstate. Active ))
  20. Throw new businessexception ("auction is not active yet .");
  21. // Auction still valid
  22. If (this. getenddate (). Before (new date ()))
  23. Throw new businessexception ("can't place new bid, auction already ended .");
  24. // Create new bid
  25. Bid newbid = new bid (bidamount, this, bidder );
  26. // Place bid for this item
  27. This. addbid (newbid );
  28. Itemdao. Update (this); // call Dao for explicit persistence
  29. Return newbid;
  30. }
  31. }

 

In this model, all business logic is in item, and transaction management is also implemented in item.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.